-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (30 loc) · 887 Bytes
/
index.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
import compression from 'compression';
import express from 'express';
import path from 'path';
const app = express();
const port = process.env.PORT || 8080;
app.use(compression());
app.enable('trust proxy');
app.get(`/.well-known/acme-challenge/${process.env.LETS_ENCRYPT_ROUTE}`, (req, res) => {
res.send(process.env.LETS_ENCRYPT_VERIFICATION);
});
app.use((req, res, next) => {
if (req.secure || req.headers.host === `localhost:${port}`) {
next();
} else {
res.redirect(`https://${req.headers.host}${req.url}`);
}
});
app.use(express.static('./build'));
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'build', 'index.html'));
});
app.listen(port, err => {
if (err) {
// eslint-disable-next-line no-console
console.log(err);
return;
}
// eslint-disable-next-line no-console
console.log(`App and API is live at http://localhost:${port}`);
});