-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
36 lines (29 loc) · 1.07 KB
/
server.js
File metadata and controls
36 lines (29 loc) · 1.07 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
import express from 'express';
import cors from 'cors';
import path from 'path';
import { fileURLToPath } from 'url';
// Import our new modular backend architecture
import { config } from './backend/config/index.js';
import routes from './backend/routes/index.js';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const app = express();
// Middleware
app.use(cors());
app.use(express.json({ limit: '50mb' }));
// Mount all backend API routes
app.use(config.apiPrefix, routes);
// Serve Frontend in Production
app.use(express.static(path.join(__dirname, 'dist')));
app.use((req, res) => {
const file = path.join(__dirname, 'dist', 'index.html');
res.sendFile(file, (err) => {
if (err) res.status(404).send("Frontend build not found. Run 'npm run build' first.");
});
});
// Start Server
app.listen(config.port, () => {
console.log(`\n✅ DSM Ops Hub Backend Server running on port ${config.port}`);
console.log(`💾 Database mapped to: ${config.dbPath}\n`);
console.log(`🏗️ Modular Architecture Pattern Active 🚀\n`);
});