-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
36 lines (28 loc) · 906 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
const express = require('express')
const path = require('path')
const compression = require('compression')
const logger = require('morgan')
// For forcing SSL on Heroku
function sslRedirect(req, res, next) {
if (process.env.NODE_ENV !== 'production')
return next()
// Check `x-forwarded-proto` header set by Heroku
const forwardedProto = req.headers['x-forwarded-proto']
const notHTTPS = forwardedProto && forwardedProto !== 'https'
if (notHTTPS) {
const url = path.join(req.get('Host'), req.url)
res.redirect(`https://${url}`)
return
}
next()
}
const app = express()
app.use(logger('dev'))
app.use(sslRedirect)
app.use(compression());
app.use(express.static(path.join(__dirname, 'public'), { maxAge: 1000 * 60 * 60 * 24 * 7 }))
app.get('*', (req, res) => {
const fileURL = path.join(__dirname, 'public', 'index.html')
res.sendFile(fileURL)
})
module.exports = app