-
Notifications
You must be signed in to change notification settings - Fork 31
/
server.js
36 lines (29 loc) · 932 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 path = require('path')
const express = require('express')
const app = express()
const port = process.env.PORT || 5000
// Redirect all HTTP traffic to HTTPS in production
if (process.env.NODE_ENV === 'production') {
app.use((req, res, next) => {
app.enable('trust proxy', 'loopback')
if (req.secure) {
return next()
}
res.redirect(`https://${req.hostname}${req.url}`)
})
}
app.use('/', express.static(path.resolve(__dirname, 'build')))
app.get('/config', (req, res) => {
res.json(
{
apiUrl: process.env.TRAVOLTA_URL || `https://travolta-production.herokuapp.com`,
}
)
})
// handle every other route with index.html, which will contain
// a script tag to your application's JavaScript file(s).
app.get('*', function (request, response){
response.sendFile(path.resolve(__dirname, 'build', 'index.html'))
})
app.listen(port)
console.log(`Serving static files on port ${port}`)