-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.ts
More file actions
30 lines (24 loc) · 777 Bytes
/
server.ts
File metadata and controls
30 lines (24 loc) · 777 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
29
30
import express from 'express';
import path from 'path';
const PORT = 8000;
const HOST = 'localhost';
const app = express();
// Logging middleware
app.use((req, res, next) => {
console.log(`${new Date().toISOString()} - ${req.method} ${req.url}`);
next();
});
// Serve static files from current directory
app.use(express.static('.'));
// Fallback for client-side routing - serve index.html for non-file routes
app.use((req, res, next) => {
// If the request has a file extension, let it 404
if (path.extname(req.path)) {
return next();
}
// Otherwise serve index.html for client-side routing
res.sendFile(path.join(process.cwd(), 'index.html'));
});
app.listen(PORT, HOST, () => {
console.log(`\n🚀 Server running at http://${HOST}:${PORT}/\n`);
});