-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
28 lines (22 loc) · 910 Bytes
/
server.js
File metadata and controls
28 lines (22 loc) · 910 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
import express from 'express';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
const __dirname = dirname(fileURLToPath(import.meta.url));
const app = express();
const PORT = process.env.PORT || 3000;
const HOST = process.env.HOST || '127.0.0.1'; // localhost only — never exposed to network
// Serve static build
app.use(express.static(join(__dirname, 'dist')));
// SPA fallback
app.get('*', (_req, res) => res.sendFile(join(__dirname, 'dist', 'index.html')));
const server = app.listen(Number(PORT), HOST, () => {
console.log(`Mipler running at http://localhost:${PORT} (bound to ${HOST})`);
});
server.on('error', (error) => {
if (error && typeof error === 'object' && 'code' in error) {
console.error(`[mipler] Failed to bind ${HOST}:${PORT} (${error.code})`);
} else {
console.error('[mipler] Failed to start the local server');
}
process.exit(1);
});