feat(native): auto-serve SPA when dist exists (unless SERVE_FRONTEND=false); add clear logging; serve index.html for /admin
Mirror to GitHub / mirror (push) Successful in 42s
Test and Lint / backend-test (push) Successful in 1m34s
Test and Lint / frontend-test (push) Successful in 2m10s
Version and Release / version-bump (push) Successful in 59s
Version and Release / trigger-drone (push) Successful in 3s

This commit is contained in:
2025-09-09 19:52:02 +02:00
parent 8404125ff0
commit fb16b7bbb8
+8 -3
View File
@@ -222,15 +222,20 @@ app.use('/api/secure-images', secureImagesRoutes);
// Optional: Serve built frontend (native installs) // Optional: Serve built frontend (native installs)
try { try {
const serveFrontend = process.env.SERVE_FRONTEND === 'true'; const serveFrontendEnv = process.env.SERVE_FRONTEND; // 'true' | 'false' | undefined
const frontendDir = process.env.FRONTEND_DIR || path.join(__dirname, '../frontend/dist'); const frontendDir = process.env.FRONTEND_DIR || path.join(__dirname, '../frontend/dist');
if (serveFrontend && fs.existsSync(frontendDir)) { const indexPath = path.join(frontendDir, 'index.html');
// Auto-serve when dist exists unless explicitly disabled
const shouldServe = (serveFrontendEnv === 'true') || ((serveFrontendEnv === undefined || serveFrontendEnv === 'auto') && fs.existsSync(indexPath));
if (shouldServe) {
logger.info(`Serving frontend from ${frontendDir}`); logger.info(`Serving frontend from ${frontendDir}`);
app.use(express.static(frontendDir)); app.use(express.static(frontendDir));
// SPA fallback for non-API routes // SPA fallback for non-API routes
app.get([ '/', '/admin', '/admin/*', '/gallery/*' ], (req, res) => { app.get([ '/', '/admin', '/admin/*', '/gallery/*' ], (req, res) => {
res.sendFile(path.join(frontendDir, 'index.html')); res.sendFile(indexPath);
}); });
} else {
logger.info('Frontend static serving disabled or dist not found', { serveFrontendEnv, frontendDir });
} }
} catch (e) { } catch (e) {
logger.warn('Failed to enable frontend static serving', { error: e.message }); logger.warn('Failed to enable frontend static serving', { error: e.message });