forked from cmda-minor-web/progressive-web-apps-2122
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
33 lines (25 loc) · 689 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const express = require('express')
const app = express()
const port = process.env.PORT || 4000
const ejs = require('ejs')
const router = require('./routes/router')
const compression = require('compression')
require('dotenv').config()
app.set('view engine', 'ejs')
app.set('views', './views/pages')
app.use(express.static('public'))
let setCache = function (req, res, next) {
const period = 60 * 5
if (req.method == 'GET') {
res.set('Cache-control', `public, max-age=${period}`)
} else {
res.set('Cache-control', `no-store`)
}
next()
}
app.use(setCache)
app.use(router)
app.use(compression())
app.listen(port, () => {
console.log(`Listening on port ${port}`)
})