sudo-saidso commited on
Commit
1f53a2f
·
verified ·
1 Parent(s): 84a1fbc

Update server/server.js

Browse files
Files changed (1) hide show
  1. server/server.js +9 -14
server/server.js CHANGED
@@ -1,21 +1,22 @@
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) => {
20
  const { inputCode, outputLanguage } = req.body;
21
  if (!inputCode || !outputLanguage) return res.status(400).json({ error: 'Missing input' });
@@ -40,11 +41,5 @@ 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
-
 
1
  import express from 'express';
2
  import cors from 'cors';
 
3
  import path from 'path';
4
+ import { GoogleGenAI } from "@google/genai";
 
 
 
5
 
6
  const app = express();
7
  app.use(cors());
8
  app.use(express.json());
9
 
 
 
 
10
  const PORT = process.env.PORT || 7860;
11
 
12
+ // Serve the Vite build folder
13
+ app.use(express.static(path.join(__dirname, '../dist')));
14
+
15
+ app.get('/', (req, res) => {
16
+ res.sendFile(path.join(__dirname, '../dist/index.html'));
17
+ });
18
+
19
+ // API endpoint
20
  app.post('/api/translate', async (req, res) => {
21
  const { inputCode, outputLanguage } = req.body;
22
  if (!inputCode || !outputLanguage) return res.status(400).json({ error: 'Missing input' });
 
41
  }
42
  });
43
 
 
 
 
 
 
44
  app.listen(PORT, () => console.log(`Server running on port ${PORT}`));
45