From 43c3c8ab86153183a5347dae12509f90af9ace32 Mon Sep 17 00:00:00 2001 From: Plena Finance Dev Date: Thu, 9 Jul 2026 14:46:30 +0530 Subject: [PATCH] feat(backend): add fallback index serving routing when website is missing --- backend/src/index.ts | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/backend/src/index.ts b/backend/src/index.ts index f131ba2..8a5909b 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -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) => {