💾 implement cache storage in all paths

master
carlos-burelo 3 years ago
parent 591ab524ab
commit fbfd99dced

@ -1,6 +1,6 @@
import axios from 'axios' import axios from 'axios'
import { NextFunction, Request, Response } from 'express'
import { parse } from 'node-html-parser' import { parse } from 'node-html-parser'
import { API } from './types' import { API } from './types'
export const headers = { export const headers = {
@ -34,4 +34,10 @@ export function attr(
) { ) {
return html.querySelector(selector)?.attributes[attribute as any] as unknown as string 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 } export { parse }

@ -1,8 +1,10 @@
import express from 'express' import express from 'express'
import routes from './router' import routes from './router'
import { cache } from './api'
const app = express() const app = express()
app.use(cache)
app.use('/', routes) app.use('/', routes)
const port = process.env.PORT || 5000 const port = process.env.PORT || 5000

Loading…
Cancel
Save