diff --git a/src/api.ts b/src/api.ts index 8540fde..5f18494 100644 --- a/src/api.ts +++ b/src/api.ts @@ -1,6 +1,6 @@ import axios from 'axios' +import { NextFunction, Request, Response } from 'express' import { parse } from 'node-html-parser' - import { API } from './types' export const headers = { @@ -34,4 +34,10 @@ export function attr( ) { return html.querySelector(selector)?.attributes[attribute as any] as unknown as string } +export const cache = (req: Request, res: Response, next: NextFunction) => { + const period = 60 * 5 + res.set('Cache-control', `public, max-age=${period}`) + next() +} + export { parse } diff --git a/src/index.ts b/src/index.ts index 430caec..3f0a9d0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,10 @@ import express from 'express' import routes from './router' +import { cache } from './api' const app = express() +app.use(cache) app.use('/', routes) const port = process.env.PORT || 5000