Spaces:
Sleeping
Sleeping
Update server/server.js
Browse files- server/server.js +15 -0
server/server.js
CHANGED
|
@@ -1,11 +1,19 @@
|
|
| 1 |
import express from 'express';
|
| 2 |
import cors from 'cors';
|
| 3 |
import { GoogleGenAI } from "@google/genai";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
const app = express();
|
| 6 |
app.use(cors());
|
| 7 |
app.use(express.json());
|
| 8 |
|
|
|
|
|
|
|
|
|
|
| 9 |
const PORT = process.env.PORT || 7860;
|
| 10 |
|
| 11 |
app.post('/api/translate', async (req, res) => {
|
|
@@ -32,4 +40,11 @@ app.post('/api/translate', async (req, res) => {
|
|
| 32 |
}
|
| 33 |
});
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
app.listen(PORT, () => console.log(`Server running on port ${PORT}`));
|
|
|
|
|
|
|
|
|
| 1 |
import express from 'express';
|
| 2 |
import cors from 'cors';
|
| 3 |
import { GoogleGenAI } from "@google/genai";
|
| 4 |
+
import path from 'path';
|
| 5 |
+
import { fileURLToPath } from 'url';
|
| 6 |
+
|
| 7 |
+
const __filename = fileURLToPath(import.meta.url);
|
| 8 |
+
const __dirname = path.dirname(__filename);
|
| 9 |
|
| 10 |
const app = express();
|
| 11 |
app.use(cors());
|
| 12 |
app.use(express.json());
|
| 13 |
|
| 14 |
+
// Serve static files (like index.html, JS, CSS)
|
| 15 |
+
app.use(express.static(path.join(__dirname, '../')));
|
| 16 |
+
|
| 17 |
const PORT = process.env.PORT || 7860;
|
| 18 |
|
| 19 |
app.post('/api/translate', async (req, res) => {
|
|
|
|
| 40 |
}
|
| 41 |
});
|
| 42 |
|
| 43 |
+
// Root route
|
| 44 |
+
app.get('/', (req, res) => {
|
| 45 |
+
res.sendFile(path.join(__dirname, '../index.html'));
|
| 46 |
+
});
|
| 47 |
+
|
| 48 |
app.listen(PORT, () => console.log(`Server running on port ${PORT}`));
|
| 49 |
+
|
| 50 |
+
|