-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
40 lines (33 loc) · 1.32 KB
/
server.js
File metadata and controls
40 lines (33 loc) · 1.32 KB
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
33
34
35
36
37
38
39
40
require('dotenv').config();
const express = require('express');
const cors = require('cors');
const path = require('path');
const apiRoutes = require('./src/routes/api');
const BrowserManager = require('./src/services/BrowserManager');
const app = express();
const PORT = process.env.PORT || 3000;
app.use(cors());
app.use(express.json());
app.use(express.static(path.join(__dirname, 'public')));
// Main OpenAI Compatible Route
app.use('/v1', apiRoutes);
// Health Check
app.get('/health', (req, res) => res.json({ status: 'ok', deepseek_proxy: true }));
app.listen(PORT, async () => {
console.log(`🚀 DeepSeek Reverse Proxy API is running on http://localhost:${PORT}`);
// Natively boot Playwright so it's ready for incoming API requests instantly
try {
await BrowserManager.initialize();
console.log("✅ Playwright Browser Engine Initialized!");
} catch (e) {
console.error("❌ Failed to initialize BrowserManager:", e);
}
});
// Graceful shutdown: Playwright MUST be closed properly or the session cookies will NOT save to disk!
process.on('SIGINT', async () => {
console.log("🛑 Shutting down proxy server safely to save your browser session...");
if (BrowserManager && BrowserManager.browser) {
await BrowserManager.browser.close();
}
process.exit();
});