-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathserver.js
More file actions
28 lines (23 loc) · 698 Bytes
/
server.js
File metadata and controls
28 lines (23 loc) · 698 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
const express = require('express')
const app = express()
let port = process.env.PORT || 3000
process.argv.forEach((val) => {
if (val.startsWith('--port')) port = val.split('=')[1];
});
if (process.env.NODE_ENV === 'production') {
app.use(requireHTTPS)
}
app.use(express.static('./dist/cbtracker'))
app.get('/*', (req, res) =>
res.sendFile('index.html', { root: 'dist/cbtracker/' })
)
app.listen(port, () => {
console.log('listening at port', port)
})
function requireHTTPS (req, res, next) {
// The 'x-forwarded-proto' check is for Heroku
if (!req.secure && req.get('x-forwarded-proto') !== 'https') {
return res.redirect('https://' + req.get('host') + req.url)
}
next()
}