feat(backend): add fallback index serving routing when website is missing
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import 'dotenv/config';
|
import 'dotenv/config';
|
||||||
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
import cors from 'cors';
|
import cors from 'cors';
|
||||||
@@ -71,9 +72,34 @@ app.get('/{*path}', (req, res, next) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
res.sendFile(path.join(publicDir, 'index.html'), (err) => {
|
// Serve the primary website if it exists
|
||||||
if (err) next();
|
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) => {
|
app.use((_req, res) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user