feat(backend): add fallback index serving routing when website is missing

This commit is contained in:
Plena Finance Dev
2026-07-09 14:46:30 +05:30
parent eab41a1bc4
commit 43c3c8ab86

View File

@@ -1,4 +1,5 @@
import 'dotenv/config';
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import cors from 'cors';
@@ -71,9 +72,34 @@ app.get('/{*path}', (req, res, next) => {
return;
}
res.sendFile(path.join(publicDir, 'index.html'), (err) => {
if (err) next();
});
// Serve the primary website if it exists
const websiteIndex = path.join(publicDir, 'index.html');
if (fs.existsSync(websiteIndex)) {
res.sendFile(websiteIndex, (err) => {
if (err) next();
});
return;
}
// Fallback to games if present
const gamesIndex = path.join(publicDir, 'games/index.html');
if (fs.existsSync(gamesIndex)) {
res.sendFile(gamesIndex, (err) => {
if (err) next();
});
return;
}
// Fallback to mobile if present
const mobileIndex = path.join(publicDir, 'mobile/index.html');
if (fs.existsSync(mobileIndex)) {
res.sendFile(mobileIndex, (err) => {
if (err) next();
});
return;
}
next();
});
app.use((_req, res) => {