feat: serve built frontend and add SPA fallback for non-API routes
This commit is contained in:
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user