-
Notifications
You must be signed in to change notification settings - Fork 0
/
index-build.js
48 lines (34 loc) · 1.08 KB
/
index-build.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
39
40
41
42
43
44
45
46
47
48
/* eslint-disable */
const _compression = require('compression');
const _compression2 = _interopRequireDefault(_compression);
const _express = require('express');
const _express2 = _interopRequireDefault(_express);
const _fs = require('fs');
const _fs2 = _interopRequireDefault(_fs);
const _path = require('path');
const _path2 = _interopRequireDefault(_path);
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : { default: obj };
}
const app = (0, _express2.default)();
const port = process.env.PORT || 8080;
app.use((0, _compression2.default)());
app.enable('trust proxy');
app.use(function(req, res, next) {
if (req.secure || req.headers.host === `localhost:${port}`) {
next();
} else {
res.redirect(`https://${req.headers.host}${req.url}`);
}
});
app.use(_express2.default.static('./build'));
app.get('*', function(req, res) {
res.sendFile(_path2.default.resolve(__dirname, 'build', 'index.html'));
});
app.listen(port, function(err) {
if (err) {
console.log(err);
return;
}
console.log(`App and API is live at http://localhost:${port}`);
});