forked from d-zone-org/d-zone
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.ts
More file actions
53 lines (42 loc) · 1.41 KB
/
index.ts
File metadata and controls
53 lines (42 loc) · 1.41 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
import express from 'express';
import path from 'path';
import { fileURLToPath } from 'url';
// ESM equivalent of __dirname
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const app = express();
const PORT = 8080;
// Add error handling
process.on('uncaughtException', (error) => {
console.error('Uncaught Exception:', error);
process.exit(1);
});
process.on('unhandledRejection', (reason, promise) => {
console.error('Unhandled Rejection at:', promise, 'reason:', reason);
process.exit(1);
});
// Serve static files from the 'dist' directory
app.use(express.static(path.join(__dirname, 'dist')));
// Add a route for the root path
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'dist', 'index.html'));
});
// Add health check endpoint
app.get('/health', (req, res) => {
res.json({ status: 'OK', timestamp: new Date().toISOString() });
});
// Add basic request logging
app.use((req, res, next) => {
console.log(`${new Date().toISOString()} ${req.method} ${req.url}`);
next();
});
const server = app.listen(PORT, () => {
console.log(`Static site served at http://localhost:${PORT}`);
console.log(`Health check available at http://localhost:${PORT}/health`);
console.log('Server is running...');
});
server.on('error', (error: any) => {
console.error('Server error:', error);
});
// Keep the process alive
process.stdin.resume();