From 531ddbee85d25ef2e0e490e2e3110f7c78dd484f Mon Sep 17 00:00:00 2001 From: 0x1d Date: Thu, 23 Oct 2025 11:38:03 +0200 Subject: [PATCH] feat: introduce routing system --- index.js | 14 +++++----- public/index.html | 16 +++++------ public/scripts/framework.js | 54 +++++++++++++++++++++++++++++++++++-- public/styles/main.css | 1 + 4 files changed, 69 insertions(+), 16 deletions(-) diff --git a/index.js b/index.js index 21b13de..5a03a94 100644 --- a/index.js +++ b/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}`); diff --git a/public/index.html b/public/index.html index b54c48b..9bc94de 100644 --- a/public/index.html +++ b/public/index.html @@ -18,7 +18,7 @@