feat: serve built frontend and add SPA fallback for non-API routes

This commit is contained in:
2025-11-13 00:45:38 +01:00
parent 338d7bc8dc
commit c11a7d47b7

View File

@@ -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')