diff --git a/backend/src/CatchAllRedirect.ts b/backend/src/CatchAllRedirect.ts new file mode 100644 index 0000000..2f923d9 --- /dev/null +++ b/backend/src/CatchAllRedirect.ts @@ -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 + }; +} \ No newline at end of file diff --git a/backend/src/main.ts b/backend/src/main.ts index c2a1009..9ab89b0 100644 --- a/backend/src/main.ts +++ b/backend/src/main.ts @@ -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