feat: introduce routing system
This commit is contained in:
14
index.js
14
index.js
@@ -19,12 +19,7 @@ const PORT = process.env.PORT || 3000;
|
||||
// Serve static files from public directory
|
||||
app.use(express.static(path.join(__dirname, 'public')));
|
||||
|
||||
// Serve the main HTML page
|
||||
app.get('/', (req, res) => {
|
||||
res.sendFile(path.join(__dirname, 'public', 'index.html'));
|
||||
});
|
||||
|
||||
// Health check endpoint
|
||||
// Health check endpoint (before catch-all route)
|
||||
app.get('/health', (req, res) => {
|
||||
res.json({
|
||||
status: 'healthy',
|
||||
@@ -34,6 +29,13 @@ app.get('/health', (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
// SPA catch-all route - serves index.html for all routes
|
||||
// This allows client-side routing to work properly
|
||||
// Using regex pattern for Express 5 compatibility
|
||||
app.get(/^\/(?!health$).*/, (req, res) => {
|
||||
res.sendFile(path.join(__dirname, 'public', 'index.html'));
|
||||
});
|
||||
|
||||
// Start the server
|
||||
app.listen(PORT, '0.0.0.0', () => {
|
||||
console.log(`SPORE UI Frontend Server is running on http://0.0.0.0:${PORT}`);
|
||||
|
||||
Reference in New Issue
Block a user