-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.ts
More file actions
64 lines (55 loc) · 1.85 KB
/
Copy pathserver.ts
File metadata and controls
64 lines (55 loc) · 1.85 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* RouteMind NER Logistics Intelligence Platform
* Full-Stack Express Server & Vite Dev Middleware
*/
import express from 'express';
import path from 'path';
import { createServer as createViteServer } from 'vite';
import { apiRouter } from './server/routes';
async function startServer() {
const app = express();
const PORT = 3000;
// Middleware for body parsing
app.use(express.json({ limit: '15mb' }));
app.use(express.urlencoded({ extended: true }));
// CORS headers for local/testing flexibility
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET, POST, PATCH, PUT, DELETE, OPTIONS');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization, x-user-role, x-user-id');
if (req.method === 'OPTIONS') {
return res.sendStatus(200);
}
next();
});
// Top-level Health Check endpoint (as required by Section 50)
app.get('/health', (req, res) => {
res.json({
status: 'ok',
service: 'routemind-ner-platform',
version: '1.0.0',
region: 'North Eastern Region (NER), India',
timestamp: new Date().toISOString()
});
});
// Mount REST API
app.use('/api', apiRouter);
// Vite middleware for development or static serving for production
if (process.env.NODE_ENV !== 'production') {
const vite = await createViteServer({
server: { middlewareMode: true },
appType: 'spa',
});
app.use(vite.middlewares);
} else {
const distPath = path.join(process.cwd(), 'dist');
app.use(express.static(distPath));
app.get('*', (req, res) => {
res.sendFile(path.join(distPath, 'index.html'));
});
}
app.listen(PORT, '0.0.0.0', () => {
console.log(`[RouteMind] Server active at http://0.0.0.0:${PORT}`);
});
}
startServer();