From faa3743569180cb1abe869e214f84d9f380c9383 Mon Sep 17 00:00:00 2001 From: capitanwesler Date: Fri, 26 Mar 2021 14:29:46 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=BDAdding=20redis=20cache=20to=20the?= =?UTF-8?q?=20routes=20where=20is=20needed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/AnimeController.ts | 326 +++++++++++++++++++++---- src/controllers/DirectoryController.ts | 96 +++++++- src/controllers/UtilsController.ts | 231 +++++++++++++++--- src/routes.ts | 18 +- 4 files changed, 570 insertions(+), 101 deletions(-) diff --git a/src/controllers/AnimeController.ts b/src/controllers/AnimeController.ts index 7005825..9629eee 100644 --- a/src/controllers/AnimeController.ts +++ b/src/controllers/AnimeController.ts @@ -77,10 +77,20 @@ export default class AnimeController { let data: any; try { - data = await requestGot(`${urls.BASE_JIKAN}schedule/${day}`, { - parse: true, - scrapy: false, - }); + const resultQueryRedis: any = await redisClient.get( + `schedule_${hashStringMd5(day)}`, + ); + + if (resultQueryRedis) { + const resultRedis: any = JSON.parse(resultQueryRedis); + + return res.status(200).json(resultRedis); + } else { + data = await requestGot(`${urls.BASE_JIKAN}schedule/${day}`, { + parse: true, + scrapy: false, + }); + } } catch (err) { return next(err); } @@ -92,6 +102,20 @@ export default class AnimeController { })); if (animeList.length > 0) { + /* Set the key in the redis cache. */ + + redisClient.set( + `schedule_${hashStringMd5(day)}`, + JSON.stringify({ day: animeList }), + ); + + /* After 24hrs expire the key. */ + + redisClient.expireat( + `schedule_${hashStringMd5(day)}`, + new Date().getTime() + 86400000, + ); + res.status(200).json({ day: animeList, }); @@ -102,20 +126,37 @@ export default class AnimeController { async top(req: Request, res: Response, next: NextFunction) { const { type, subtype, page } = req.params; - let data: any; try { - if (subtype !== undefined) { - data = await requestGot( - `${urls.BASE_JIKAN}top/${type}/${page}/${subtype}`, - { parse: true, scrapy: false }, + let resultQueryRedis: any; + + if (subtype) { + resultQueryRedis = await redisClient.get( + `top_${hashStringMd5(`${type}:${subtype}:${page}`)}`, ); } else { - data = await requestGot(`${urls.BASE_JIKAN}top/${type}/${page}`, { - parse: true, - scrapy: false, - }); + resultQueryRedis = await redisClient.get( + `top_${hashStringMd5(`${type}:${page}`)}`, + ); + } + + if (resultQueryRedis) { + const resultRedis: any = JSON.parse(resultQueryRedis); + + return res.status(200).json(resultRedis); + } else { + if (subtype !== undefined) { + data = await requestGot( + `${urls.BASE_JIKAN}top/${type}/${page}/${subtype}`, + { parse: true, scrapy: false }, + ); + } else { + data = await requestGot(`${urls.BASE_JIKAN}top/${type}/${page}`, { + parse: true, + scrapy: false, + }); + } } } catch (err) { return next(err); @@ -133,6 +174,33 @@ export default class AnimeController { })); if (top.length > 0) { + /* Set the key in the redis cache. */ + if (subtype) { + redisClient.set( + `top_${hashStringMd5(`${type}:${subtype}:${page}`)}`, + JSON.stringify({ top }), + ); + } else { + redisClient.set( + `top_${hashStringMd5(`${type}:${page}`)}`, + JSON.stringify({ top }), + ); + } + + /* After 24hrs expire the key. */ + + if (subtype) { + redisClient.expireat( + `top_${hashStringMd5(`${type}:${subtype}:${page}`)}`, + new Date().getTime() + 86400000, + ); + } else { + redisClient.expireat( + `top_${hashStringMd5(`${type}:${page}`)}`, + new Date().getTime() + 86400000, + ); + } + return res.status(200).json({ top }); } else { return res.status(400).json({ message: 'Aruppi lost in the shell' }); @@ -171,10 +239,23 @@ export default class AnimeController { let episodes: Episode[] = []; try { - data = await requestGot(`${urls.BASE_ANIMEFLV_JELU}LatestEpisodesAdded`, { - parse: true, - scrapy: false, - }); + const resultQueryRedis: any = await redisClient.get( + `lastEpisodes_${hashStringMd5('lastEpisodes')}`, + ); + + if (resultQueryRedis) { + const resultRedis: any = JSON.parse(resultQueryRedis); + + return res.status(200).json(resultRedis); + } else { + data = await requestGot( + `${urls.BASE_ANIMEFLV_JELU}LatestEpisodesAdded`, + { + parse: true, + scrapy: false, + }, + ); + } } catch (err) { return next(err); } @@ -192,6 +273,20 @@ export default class AnimeController { } if (episodes.length > 0) { + /* Set the key in the redis cache. */ + + redisClient.set( + `lastEpisodes_${hashStringMd5('lastEpisodes')}`, + JSON.stringify({ episodes }), + ); + + /* After 24hrs expire the key. */ + + redisClient.expireat( + `lastEpisodes_${hashStringMd5('lastEpisodes')}`, + new Date().getTime() + 86400000, + ); + res.status(200).json({ episodes, }); @@ -206,15 +301,25 @@ export default class AnimeController { let data: any; try { - data = await requestGot( - `${urls.BASE_ANIMEFLV_JELU}${ - url.charAt(0).toUpperCase() + url.slice(1) - }/${type}/${page}`, - { - parse: true, - scrapy: false, - }, + const resultQueryRedis: any = await redisClient.get( + `contentTv_${hashStringMd5(`${type}:${page}`)}`, ); + + if (resultQueryRedis) { + const resultRedis: any = JSON.parse(resultQueryRedis); + + return res.status(200).json(resultRedis); + } else { + data = await requestGot( + `${urls.BASE_ANIMEFLV_JELU}${ + url.charAt(0).toUpperCase() + url.slice(1) + }/${type}/${page}`, + { + parse: true, + scrapy: false, + }, + ); + } } catch (err) { return next(err); } @@ -236,6 +341,20 @@ export default class AnimeController { }); if (animes.length > 0) { + /* Set the key in the redis cache. */ + + redisClient.set( + `contentTv_${hashStringMd5(`${type}:${page}`)}`, + JSON.stringify({ animes }), + ); + + /* After 24hrs expire the key. */ + + redisClient.expireat( + `contentTv_${hashStringMd5(`${type}:${page}`)}`, + new Date().getTime() + 86400000, + ); + res.status(200).json({ animes, }); @@ -250,15 +369,25 @@ export default class AnimeController { let data: any; try { - data = await requestGot( - `${urls.BASE_ANIMEFLV_JELU}${ - url.charAt(0).toUpperCase() + url.slice(1) - }/${type}/${page}`, - { - parse: true, - scrapy: false, - }, + const resultQueryRedis: any = await redisClient.get( + `contentSpecial_${hashStringMd5(`${type}:${page}`)}`, ); + + if (resultQueryRedis) { + const resultRedis: any = JSON.parse(resultQueryRedis); + + return res.status(200).json(resultRedis); + } else { + data = await requestGot( + `${urls.BASE_ANIMEFLV_JELU}${ + url.charAt(0).toUpperCase() + url.slice(1) + }/${type}/${page}`, + { + parse: true, + scrapy: false, + }, + ); + } } catch (err) { return next(err); } @@ -280,6 +409,20 @@ export default class AnimeController { }); if (animes.length > 0) { + /* Set the key in the redis cache. */ + + redisClient.set( + `contentSpecial_${hashStringMd5(`${type}:${page}`)}`, + JSON.stringify({ animes }), + ); + + /* After 24hrs expire the key. */ + + redisClient.expireat( + `contentSpecial_${hashStringMd5(`${type}:${page}`)}`, + new Date().getTime() + 86400000, + ); + res.status(200).json({ animes, }); @@ -294,15 +437,25 @@ export default class AnimeController { let data: any; try { - data = await requestGot( - `${urls.BASE_ANIMEFLV_JELU}${ - url.charAt(0).toUpperCase() + url.slice(1) - }/${type}/${page}`, - { - parse: true, - scrapy: false, - }, + const resultQueryRedis: any = await redisClient.get( + `contentOva_${hashStringMd5(`${type}:${page}`)}`, ); + + if (resultQueryRedis) { + const resultRedis: any = JSON.parse(resultQueryRedis); + + return res.status(200).json(resultRedis); + } else { + data = await requestGot( + `${urls.BASE_ANIMEFLV_JELU}${ + url.charAt(0).toUpperCase() + url.slice(1) + }/${type}/${page}`, + { + parse: true, + scrapy: false, + }, + ); + } } catch (err) { return next(err); } @@ -324,6 +477,20 @@ export default class AnimeController { }); if (animes.length > 0) { + /* Set the key in the redis cache. */ + + redisClient.set( + `contentOva_${hashStringMd5(`${type}:${page}`)}`, + JSON.stringify({ animes }), + ); + + /* After 24hrs expire the key. */ + + redisClient.expireat( + `contentOva_${hashStringMd5(`${type}:${page}`)}`, + new Date().getTime() + 86400000, + ); + res.status(200).json({ animes, }); @@ -338,15 +505,25 @@ export default class AnimeController { let data: any; try { - data = await requestGot( - `${urls.BASE_ANIMEFLV_JELU}${ - url.charAt(0).toUpperCase() + url.slice(1) - }/${type}/${page}`, - { - parse: true, - scrapy: false, - }, + const resultQueryRedis: any = await redisClient.get( + `contentMovie_${hashStringMd5(`${type}:${page}`)}`, ); + + if (resultQueryRedis) { + const resultRedis: any = JSON.parse(resultQueryRedis); + + return res.status(200).json(resultRedis); + } else { + data = await requestGot( + `${urls.BASE_ANIMEFLV_JELU}${ + url.charAt(0).toUpperCase() + url.slice(1) + }/${type}/${page}`, + { + parse: true, + scrapy: false, + }, + ); + } } catch (err) { return next(err); } @@ -368,6 +545,20 @@ export default class AnimeController { }); if (animes.length > 0) { + /* Set the key in the redis cache. */ + + redisClient.set( + `contentMovie_${hashStringMd5(`${type}:${page}`)}`, + JSON.stringify({ animes }), + ); + + /* After 24hrs expire the key. */ + + redisClient.expireat( + `contentMovie_${hashStringMd5(`${type}:${page}`)}`, + new Date().getTime() + 86400000, + ); + res.status(200).json({ animes, }); @@ -379,17 +570,48 @@ export default class AnimeController { async getEpisodes(req: Request, res: Response, next: NextFunction) { const { title } = req.params; let searchAnime: ModelA | null; + let episodes: any; try { - searchAnime = await AnimeModel.findOne({ title: { $eq: title } }); + const resultQueryRedis: any = await redisClient.get( + `episodes_${hashStringMd5(title)}`, + ); + + if (resultQueryRedis) { + const resultRedis: any = JSON.parse(resultQueryRedis); + + return res.status(200).json(resultRedis); + } else { + searchAnime = await AnimeModel.findOne({ title: { $eq: title } }); + } } catch (err) { return next(err); } if (!searchAnime?.jkanime) { - res.status(200).json({ episodes: await animeFlvInfo(searchAnime?.id) }); + episodes = await animeFlvInfo(searchAnime?.id); } else { - res.status(200).json({ episodes: await jkanimeInfo(searchAnime?.id) }); + episodes = await jkanimeInfo(searchAnime?.id); + } + + if (episodes) { + /* Set the key in the redis cache. */ + + redisClient.set( + `episodes_${hashStringMd5(title)}`, + JSON.stringify({ episodes }), + ); + + /* After 24hrs expire the key. */ + + redisClient.expireat( + `episodes_${hashStringMd5(title)}`, + new Date().getTime() + 86400000, + ); + + res.status(200).json({ episodes }); + } else { + res.status(500).json({ message: 'Aruppi lost in the shell' }); } } diff --git a/src/controllers/DirectoryController.ts b/src/controllers/DirectoryController.ts index 7890b37..0600ee3 100644 --- a/src/controllers/DirectoryController.ts +++ b/src/controllers/DirectoryController.ts @@ -111,10 +111,20 @@ export default class DirectoryController { let data: any; try { - data = await requestGot(`${urls.BASE_JIKAN}season/${year}/${type}`, { - scrapy: false, - parse: true, - }); + const resultQueryRedis: any = await redisClient.get( + `season_${hashStringMd5(`${year}:${type}`)}`, + ); + + if (resultQueryRedis) { + const resultRedis: any = JSON.parse(resultQueryRedis); + + return res.status(200).json(resultRedis); + } else { + data = await requestGot(`${urls.BASE_JIKAN}season/${year}/${type}`, { + scrapy: false, + parse: true, + }); + } } catch (err) { return next(err); } @@ -128,6 +138,20 @@ export default class DirectoryController { }); if (season.length > 0) { + /* Set the key in the redis cache. */ + + redisClient.set( + `season_${hashStringMd5(`${year}:${type}`)}`, + JSON.stringify({ season }), + ); + + /* After 24hrs expire the key. */ + + redisClient.expireat( + `season_${hashStringMd5(`${year}:${type}`)}`, + new Date().getTime() + 86400000, + ); + res.status(200).json({ season, }); @@ -140,10 +164,20 @@ export default class DirectoryController { let data: any; try { - data = await requestGot(`${urls.BASE_JIKAN}season/archive`, { - parse: true, - scrapy: false, - }); + const resultQueryRedis: any = await redisClient.get( + `allSeasons_${hashStringMd5('allSeasons')}`, + ); + + if (resultQueryRedis) { + const resultRedis: any = JSON.parse(resultQueryRedis); + + return res.status(200).json(resultRedis); + } else { + data = await requestGot(`${urls.BASE_JIKAN}season/archive`, { + parse: true, + scrapy: false, + }); + } } catch (err) { return next(err); } @@ -156,6 +190,20 @@ export default class DirectoryController { }); if (archive.length > 0) { + /* Set the key in the redis cache. */ + + redisClient.set( + `allSeasons_${hashStringMd5('allSeasons')}`, + JSON.stringify({ archive }), + ); + + /* After 24hrs expire the key. */ + + redisClient.expireat( + `allSeasons_${hashStringMd5('allSeasons')}`, + new Date().getTime() + 86400000, + ); + res.status(200).json({ archive }); } else { res.status(500).json({ message: 'Aruppi lost in the shell' }); @@ -166,10 +214,20 @@ export default class DirectoryController { let data: any; try { - data = await requestGot(`${urls.BASE_JIKAN}season/later`, { - parse: true, - scrapy: false, - }); + const resultQueryRedis: any = await redisClient.get( + `laterSeasons_${hashStringMd5('laterSeasons')}`, + ); + + if (resultQueryRedis) { + const resultRedis: any = JSON.parse(resultQueryRedis); + + return res.status(200).json(resultRedis); + } else { + data = await requestGot(`${urls.BASE_JIKAN}season/later`, { + parse: true, + scrapy: false, + }); + } } catch (err) { return next(err); } @@ -183,6 +241,20 @@ export default class DirectoryController { }); if (future.length > 0) { + /* Set the key in the redis cache. */ + + redisClient.set( + `laterSeasons_${hashStringMd5('laterSeasons')}`, + JSON.stringify({ future }), + ); + + /* After 24hrs expire the key. */ + + redisClient.expireat( + `laterSeasons_${hashStringMd5('laterSeasons')}`, + new Date().getTime() + 86400000, + ); + res.status(200).json({ future }); } else { res.status(500).json({ message: 'Aruppi lost in the shell' }); diff --git a/src/controllers/UtilsController.ts b/src/controllers/UtilsController.ts index 61d1598..63bc995 100644 --- a/src/controllers/UtilsController.ts +++ b/src/controllers/UtilsController.ts @@ -11,6 +11,12 @@ import ThemeParser from '../utils/animeTheme'; import { structureThemes } from '../utils/util'; import { getThemes } from '../utils/util'; import WaifuModel, { Waifu } from '../database/models/waifu.model'; +import util from 'util'; +import { hashStringMd5 } from '../utils/util'; +import { redisClient } from '../database/connection'; + +// @ts-ignore +redisClient.get = util.promisify(redisClient.get); /* UtilsController - controller to parse the @@ -63,7 +69,17 @@ export default class UtilsController { let feed: CustomFeed & Parser.Output; try { - feed = await parser.parseURL(urls.BASE_IVOOX); + const resultQueryRedis: any = await redisClient.get( + `anitakume_${hashStringMd5('anitakume')}`, + ); + + if (resultQueryRedis) { + const resultRedis: any = JSON.parse(resultQueryRedis); + + return res.status(200).json(resultRedis); + } else { + feed = await parser.parseURL(urls.BASE_IVOOX); + } } catch (err) { return next(err); } @@ -100,6 +116,20 @@ export default class UtilsController { }); if (podcast.length > 0) { + /* Set the key in the redis cache. */ + + redisClient.set( + `anitakume_${hashStringMd5('anitakume')}`, + JSON.stringify({ podcast }), + ); + + /* After 24hrs expire the key. */ + + redisClient.expireat( + `anitakume_${hashStringMd5('anitakume')}`, + new Date().getTime() + 86400000, + ); + res.status(200).json({ podcast }); } else { res.status(500).json({ message: 'Aruppi lost in the shell' }); @@ -128,28 +158,56 @@ export default class UtilsController { ]; try { - for (const rssPage of pagesRss) { - const feed = await parser.parseURL(rssPage.url); - - feed.items.forEach((item: any) => { - const formattedObject: News = { - title: item.title, - url: item.link, - author: feed.title?.includes('Crunchyroll') - ? 'Crunchyroll' - : feed.title, - thumbnail: obtainPreviewNews(item['content:encoded']), - content: item['content:encoded'], - }; - - news.push(formattedObject); - }); + const resultQueryRedis: any = await redisClient.get( + `news_${hashStringMd5('news')}`, + ); + + if (resultQueryRedis) { + const resultRedis: any = JSON.parse(resultQueryRedis); + + return res.status(200).json(resultRedis); + } else { + for (const rssPage of pagesRss) { + const feed = await parser.parseURL(rssPage.url); + + feed.items.forEach((item: any) => { + const formattedObject: News = { + title: item.title, + url: item.link, + author: feed.title?.includes('Crunchyroll') + ? 'Crunchyroll' + : feed.title, + thumbnail: obtainPreviewNews(item['content:encoded']), + content: item['content:encoded'], + }; + + news.push(formattedObject); + }); + } } } catch (err) { return next(err); } - res.json({ news }); + if (news.length > 0) { + /* Set the key in the redis cache. */ + + redisClient.set( + `news_${hashStringMd5('news')}`, + JSON.stringify({ news }), + ); + + /* After 24hrs expire the key. */ + + redisClient.expireat( + `news_${hashStringMd5('news')}`, + new Date().getTime() + 7200000, + ); + + res.status(200).json({ news }); + } else { + res.status(500).json({ message: 'Aruppi lost in the shell' }); + } } async getImages(req: Request, res: Response, next: NextFunction) { @@ -157,10 +215,20 @@ export default class UtilsController { let data: any; try { - data = await requestGot( - `${urls.BASE_QWANT}count=51&q=${title}&t=images&safesearch=1&locale=es_ES&uiv=4`, - { scrapy: false, parse: true }, + const resultQueryRedis: any = await redisClient.get( + `images_${hashStringMd5(title)}`, ); + + if (resultQueryRedis) { + const resultRedis: any = JSON.parse(resultQueryRedis); + + return res.status(200).json(resultRedis); + } else { + data = await requestGot( + `${urls.BASE_QWANT}count=51&q=${title}&t=images&safesearch=1&locale=es_ES&uiv=4`, + { scrapy: false, parse: true }, + ); + } } catch (err) { return next(err); } @@ -174,6 +242,20 @@ export default class UtilsController { }); if (results.length > 0) { + /* Set the key in the redis cache. */ + + redisClient.set( + `images_${hashStringMd5(title)}`, + JSON.stringify({ images: results }), + ); + + /* After 24hrs expire the key. */ + + redisClient.expireat( + `images_${hashStringMd5(title)}`, + new Date().getTime() + 86400000, + ); + res.status(200).json({ images: results }); } else { res.status(500).json({ message: 'Aruppi lost in the shell' }); @@ -185,10 +267,20 @@ export default class UtilsController { let data: any; try { - data = await requestGot( - `${urls.BASE_YOUTUBE}${channelId}&part=snippet,id&order=date&maxResults=50`, - { scrapy: false, parse: true }, + const resultQueryRedis: any = await redisClient.get( + `videos_${hashStringMd5(channelId)}`, ); + + if (resultQueryRedis) { + const resultRedis: any = JSON.parse(resultQueryRedis); + + return res.status(200).json(resultRedis); + } else { + data = await requestGot( + `${urls.BASE_YOUTUBE}${channelId}&part=snippet,id&order=date&maxResults=50`, + { scrapy: false, parse: true }, + ); + } } catch (err) { return next(err); } @@ -204,6 +296,20 @@ export default class UtilsController { }); if (results.length > 0) { + /* Set the key in the redis cache. */ + + redisClient.set( + `videos_${hashStringMd5(channelId)}`, + JSON.stringify({ videos: results }), + ); + + /* After 24hrs expire the key. */ + + redisClient.expireat( + `videos_${hashStringMd5(channelId)}`, + new Date().getTime() + 86400000, + ); + res.status(200).json({ videos: results }); } else { res.status(500).json({ message: 'Aruppi lost in the shell' }); @@ -341,12 +447,36 @@ export default class UtilsController { let themes: any; try { - themes = await structureThemes(await themeParser.serie(title), true); + const resultQueryRedis: any = await redisClient.get( + `oped_${hashStringMd5(title)}`, + ); + + if (resultQueryRedis) { + const resultRedis: any = JSON.parse(resultQueryRedis); + + return res.status(200).json(resultRedis); + } else { + themes = await structureThemes(await themeParser.serie(title), true); + } } catch (err) { return next(err); } if (themes) { + /* Set the key in the redis cache. */ + + redisClient.set( + `oped_${hashStringMd5(title)}`, + JSON.stringify({ themes }), + ); + + /* After 24hrs expire the key. */ + + redisClient.expireat( + `oped_${hashStringMd5(title)}`, + new Date().getTime() + 86400000, + ); + res.status(200).json({ themes }); } else { res.status(500).json({ message: 'Aruppi lost in the shell' }); @@ -356,18 +486,63 @@ export default class UtilsController { async getThemesYear(req: Request, res: Response, next: NextFunction) { const { year } = req.params; let themes: any; + let resultQueryRedis: any; try { - if (year === undefined) { - themes = await themeParser.allYears(); + if (year) { + resultQueryRedis = await redisClient.get( + `themesyear_${hashStringMd5(year)}`, + ); + } else { + resultQueryRedis = await redisClient.get( + `themesyear_${hashStringMd5('allYear')}`, + ); + } + + if (resultQueryRedis) { + const resultRedis: any = JSON.parse(resultQueryRedis); + + return res.status(200).json(resultRedis); } else { - themes = await structureThemes(await themeParser.year(year), false); + if (year === undefined) { + themes = await themeParser.allYears(); + } else { + themes = await structureThemes(await themeParser.year(year), false); + } } } catch (err) { return next(err); } if (themes.length > 0) { + /* Set the key in the redis cache. */ + + if (year) { + redisClient.set( + `themesyear_${hashStringMd5(year)}`, + JSON.stringify({ themes }), + ); + } else { + redisClient.set( + `themesyear_${hashStringMd5('allYear')}`, + JSON.stringify({ themes }), + ); + } + + /* After 24hrs expire the key. */ + + if (year) { + redisClient.expireat( + `themesyear_${hashStringMd5(year)}`, + new Date().getTime() + 86400000, + ); + } else { + redisClient.expireat( + `themesyear_${hashStringMd5('allYear')}`, + new Date().getTime() + 86400000, + ); + } + res.status(200).json({ themes }); } else { res.status(500).json({ message: 'Aruppi lost in the shell' }); diff --git a/src/routes.ts b/src/routes.ts index b13b744..b18212d 100644 --- a/src/routes.ts +++ b/src/routes.ts @@ -116,16 +116,16 @@ routes.get('/api/v4/platforms/:id?', utilsController.getPlatforms); routes.get('/api/v4/generateWaifu/', utilsController.getWaifuRandom); /* 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(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.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) => {