forked from fdnd-task-archive/serverside-optimization
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
34 lines (27 loc) 路 886 Bytes
/
app.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
34
const express = require('express')
const path = require('path')
const compression = require('compression')
const app = express()
const PORT = process.env.PORT || 3000
//Routes
const indexRoute = require('./routes/index')
const aboutRoute = require('./routes/about')
const detailRoute = require('./routes/detail')
app.set('views', path.join(__dirname + '/views'))
app.set('view engine', 'ejs')
app.use(express.static(path.join(__dirname, '/public')))
// Cache Headers
app.use((req, res, next) => {
res.set('Cache-control', 'public, max-age=300')
next()
})
// compress all response
app.use(compression())
app.use('/', indexRoute)
app.use('/book', detailRoute)
app.use('/about', aboutRoute)
// Catch 404 and forward to error handler
app.use(function (req, res, next) {
res.status(404).render('error')
})
app.listen(PORT, () => console.log(`Listening on http://[::]:${PORT}`))