diff --git a/package.json b/package.json index ccd5474..73e63b8 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,11 @@ "name": "Darkangeel", "url": "https://github.com/Darkangeel-hd", "reason": "System administration authority (SYSADM)" + }, + { + "name": "Capitanwesler", + "url": "https://github.com/capitanwesler", + "reason": "Backend and Frontend developer" } ], "engines": { diff --git a/src/routes.ts b/src/routes.ts index fc7cf44..5ec3274 100644 --- a/src/routes.ts +++ b/src/routes.ts @@ -1,4 +1,4 @@ -import { Router, Request, Response } from 'express'; +import { Router, Request, Response, NextFunction } from 'express'; import AnimeController from './controllers/AnimeController'; import DirectoryController from './controllers/DirectoryController'; import UtilsController from './controllers/UtilsController'; @@ -111,4 +111,28 @@ routes.get('/api/v4/artists/:id?', utilsController.getArtist); routes.get('/api/v4/destAnimePlatforms', utilsController.getDestAnimePlatforms); routes.get('/api/v4/platforms/:id?', utilsController.getPlatforms); +/* Routes to handling the v3 deprecated */ +// routes.get('/api/v3/*', (req: Request, res: Response, next: NextFunction) => { +// res.status(302).redirect('/api/v2'); +// }); + +// routes.get('/api/v3', (req: Request, res: Response, next: NextFunction) => { +// res.status(200).json({ +// message: +// 'Sorry, version v3 is not avaiable, if you want to see content go to v4', +// }); +// }); + +/* Routes to handling the v2 deprecated */ +routes.get('/api/v2/*', (req: Request, res: Response, next: NextFunction) => { + res.status(302).redirect('/api/v2'); +}); + +routes.get('/api/v2', (req: Request, res: Response, next: NextFunction) => { + res.status(200).json({ + message: + 'Sorry, version v2 is not avaiable, if you want to see content go to v4', + }); +}); + export default routes; diff --git a/src/server.ts b/src/server.ts index ffb21af..daf3468 100644 --- a/src/server.ts +++ b/src/server.ts @@ -8,6 +8,7 @@ import { // createConnectionRedis, } from './database/connection'; import routes from './routes'; +import { Server } from 'node:http'; const app: Application = express(); @@ -34,4 +35,13 @@ app.use(errorHandler); is going to listen in the server. ex: PORT=3000. */ -app.listen(process.env.PORT_LISTEN || 3000); +const server: Server = app.listen(process.env.PORT_LISTEN || 3000); + +function shutdown(): void { + server.close(); + process.exit(); +} + +process.on('SIGINT', shutdown); +process.on('SIGQUIT', shutdown); +process.on('SIGTERM', shutdown);