-
Notifications
You must be signed in to change notification settings - Fork 0
/
httpsServer.js
44 lines (34 loc) · 1.22 KB
/
httpsServer.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
var express = require('express');
var cors = require('cors');
var compression = require('compression');
var path = require('path');
var https = require('https');
const app = express();
app.use(compression());
app.use(cors({
origin: true,
methods: 'POST, GET, PUT, DELETE, OPTIONS',
exposedHeaders: 'Content-Range, X-Content-Range',
credentials: true,
allowedHeaders: 'Cache-Control, Origin, Authorization, Content-Type, X-Requested-With',
}));
const DIST_FOLDER = path.join(process.cwd(), 'dist');
app.get('*', express.static(path.join(DIST_FOLDER, '')));
app.get('*', (req, res) => {
res.sendFile(path.join(DIST_FOLDER, '') + '/index.html');
});
app.use(express.static('/dist'));
app.get('*', function (req, res) {
res.setHeader("X-Frame-Options", "DENY");
res.sendFile('/dist/index.html', { root: __dirname });
})
app.listen(process.env.PORT || 4300, function () {
console.log("HTTP server started listening on port: %s", process.env.PORT || 4300);
});
const options = {
cert: fs.readFileSync(`certificate.pem`),
key: fs.readFileSync(`privateKey.pem`)
};
https.createServer(options, app).listen(config.PORT, () => {
console.log(`HTTPS server started listening on port: ${config.PORT}`);
});