-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathserver.js
More file actions
29 lines (24 loc) · 832 Bytes
/
server.js
File metadata and controls
29 lines (24 loc) · 832 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
29
const path = require('path');
const compression = require('compression');
const express = require('express');
const enforce = require('express-sslify');
const app = express();
const staticMiddleware = express.static(path.join(__dirname, '/docs'));
const spaMiddleware = (req, res) => {
res.sendFile(path.join(__dirname, '/docs/index.html'));
};
app.set('x-powered-by', false);
if (process.env.NODE_ENV !== 'development') {
app.use(enforce.HTTPS({
trustProtoHeader: true,
}));
}
app.use(compression());
app.use('/', staticMiddleware);
app.use('/optn.club', staticMiddleware);
app.use(spaMiddleware);
// app.get('*', (req, res) =>
// res.sendFile(path.join(__dirname, '/docs/index.html'))
// );
const port = process.env.PORT || 8080;
app.listen(port, () => console.info(`Express server listening on port ${port}.`));