forked from cmda-minor-web-1718/performance-matters-16-17
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
executable file
·41 lines (34 loc) · 979 Bytes
/
server.js
File metadata and controls
executable file
·41 lines (34 loc) · 979 Bytes
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
35
36
37
38
39
40
41
const path = require('path')
const express = require('express')
const nunjucks = require('nunjucks')
const compression = require('compression')
const routeStatic = require('./lib/route-static')
const redirectIndices = require('./lib/redirect-indices')
const app = express()
const baseDir = 'build'
const port = process.env.PORT || 3004
app.use(compression({
threshold: 0,
filter: () => true
}))
app.set('etag', false)
app.use((req, res, next) => {
res.removeHeader('X-Powered-By')
next()
})
// static routes
app.use(routeStatic)
app.use('/static', express.static(path.join(__dirname, baseDir), {etag: false, lastModified: false}))
// dynamic pages
app.use(redirectIndices)
nunjucks.configure(baseDir, {
autoescape: true,
express: app,
watch: true
})
app.get('*', (req, res) => {
res.render(path.join('./', req.url, 'index.html'), {})
})
app.listen(port, function (err) {
return err ? console.error(err) : console.log(`app running on http://localhost:${port}`)
})