diff --git a/backend/server.js b/backend/server.js index 06bc445..5ca2c41 100644 --- a/backend/server.js +++ b/backend/server.js @@ -155,6 +155,19 @@ app.delete('/api/counters/:id', async (req, res) => { } }) + +// Serve built frontend (production) if it exists +const FRONTEND_DIST = path.join(__dirname, '..', 'frontend', 'dist') +if (fs.existsSync(FRONTEND_DIST)) { + app.use(express.static(FRONTEND_DIST)) + + // SPA fallback: serve index.html for any non-API route + app.get('/*path', (req, res) => { + if (req.path.startsWith('/api')) return res.status(404).end() + res.sendFile(path.join(FRONTEND_DIST, 'index.html')) + }) +} + // graceful shutdown: ensure Prisma disconnects process.on('SIGINT', async () => { log.info('shutting down')