backend: added catch all redirect to index so that /about does not fail to load in production
This commit is contained in:
8
backend/src/CatchAllRedirect.ts
Normal file
8
backend/src/CatchAllRedirect.ts
Normal 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
|
||||
};
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import {MangaUpdatesCache} from './cache/MangaUpdatesCache.js';
|
||||
import * as fs from 'fs';
|
||||
import {MangaDexCache} from './cache/MangaDexCache';
|
||||
import mangaDexRouter from './router/MangaDexRouter';
|
||||
import catchAllRedirect from './CatchAllRedirect';
|
||||
import exceptionHandler from './ExceptionHandler';
|
||||
|
||||
const config = JSON.parse(fs.readFileSync('config.json').toString());
|
||||
@@ -27,6 +28,7 @@ app.use('/anilist', aniListRouter());
|
||||
app.use('/mangadex', mangaDexRouter(mangaDexCache));
|
||||
app.use('/mangaupdates', mangaUpdatesRouter(mangaUpdatesCache));
|
||||
app.use(express.static('_client')); //for production
|
||||
app.use(catchAllRedirect(app, '/'));
|
||||
app.use(exceptionHandler());
|
||||
|
||||
//start
|
||||
|
||||
Reference in New Issue
Block a user