-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
32 lines (26 loc) · 871 Bytes
/
server.js
File metadata and controls
32 lines (26 loc) · 871 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import express from 'express';
import cors from 'cors';
import dotenv from 'dotenv';
import url from 'url';
import path from 'path';
dotenv.config();
// We need to dynamically import the backend API because the project uses "type": "module"
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
const app = express();
app.use(cors());
app.use(express.json());
// Load Vercel handler
const chatPath = path.join(__dirname, 'api', 'chat.js');
let chatHandler = await import(url.pathToFileURL(chatPath).href).then(m => m.default);
app.post('/api/chat', async (req, res) => {
try {
await chatHandler(req, res);
} catch (e) {
console.error(e);
res.status(500).json({ error: e.message });
}
});
const PORT = 3000;
app.listen(PORT, () => {
console.log(`Development API server running on http://localhost:${PORT}`);
});