-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
29 lines (23 loc) · 827 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
const express = require('express');
const path = require('path');
const compression = require('compression');
const enforce = require('express-sslify');
// App initialization
const app = express();
const port = process.env.PORT || process.env.SMARTBRAIN_PORT || 5004;
if (process.env.NODE_ENV === 'production') {
app.use(compression());
app.use(enforce.HTTPS({ trustProtoHeader: true }));
// Serving static files
app.use(express.static(path.join(__dirname, 'build')));
app.get('*', function (req, res) {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
}
app.get('/service-worker.js', (req, res) => {
res.sendFile(path.resolve(__dirname, '..', 'build', 'service-worker.js'));
});
app.listen(port, (error) => {
if (error) throw error;
console.log('Server running on port ' + port);
});