-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathserver.js
38 lines (32 loc) · 861 Bytes
/
server.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
35
36
37
38
const fs = require('fs')
const path = require('path')
const express = require('express')
const compression = require('compression')
const microcache = require('route-cache')
const app = express()
const serve = (_path) => express.static(path.resolve(__dirname, _path))
app.use(compression({ threshold: 0 }))
app.use((req, res, next) => {
const mimes = [
'ttf',
'otf',
'png',
'svg',
'jpg',
'jpeg',
]
for (const mime of mimes) {
if (req.path.endsWith(mime)) {
res.set('Cache-Control', 'max-age=31536000')
return next()
}
}
next()
})
app.use('/', serve('./build'))
app.use('/wallet', serve('./build'))
app.use('/wallet/*', serve('./build'))
app.use(microcache.cacheSeconds(1, req => req.originalUrl))
const port = 4000
app.listen(port, () => console.log(`Listening on port ${port}`))
module.exports = app