backend: added catch all redirect to index so that /about does not fail to load in production

This commit is contained in:
wea_ondara
2023-11-25 19:28:54 +01:00
parent 2db551e476
commit 9279002794
2 changed files with 10 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
import {Express, NextFunction, Request, RequestHandler, Response} from 'express';
export default function catchAllRedirect(app: Express, path: string): RequestHandler {
return (req: Request, res: Response, next: NextFunction) => {
req.url = path;
(app as any).handle(req, res); //handle() is not exposed by .d.ts files
};
}

View File

@@ -7,6 +7,7 @@ import {MangaUpdatesCache} from './cache/MangaUpdatesCache.js';
import * as fs from 'fs'; import * as fs from 'fs';
import {MangaDexCache} from './cache/MangaDexCache'; import {MangaDexCache} from './cache/MangaDexCache';
import mangaDexRouter from './router/MangaDexRouter'; import mangaDexRouter from './router/MangaDexRouter';
import catchAllRedirect from './CatchAllRedirect';
import exceptionHandler from './ExceptionHandler'; import exceptionHandler from './ExceptionHandler';
const config = JSON.parse(fs.readFileSync('config.json').toString()); const config = JSON.parse(fs.readFileSync('config.json').toString());
@@ -27,6 +28,7 @@ app.use('/anilist', aniListRouter());
app.use('/mangadex', mangaDexRouter(mangaDexCache)); app.use('/mangadex', mangaDexRouter(mangaDexCache));
app.use('/mangaupdates', mangaUpdatesRouter(mangaUpdatesCache)); app.use('/mangaupdates', mangaUpdatesRouter(mangaUpdatesCache));
app.use(express.static('_client')); //for production app.use(express.static('_client')); //for production
app.use(catchAllRedirect(app, '/'));
app.use(exceptionHandler()); app.use(exceptionHandler());
//start //start