-
Notifications
You must be signed in to change notification settings - Fork 0
/
httpserver.js
53 lines (39 loc) · 1.4 KB
/
httpserver.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
49
50
51
52
53
var express = require('express');
var cors = require('cors');
var compression = require('compression');
var path = require('path');
var https = require('https');
var http = require('http');
var fs = require('fs');
const app = express();
const PORT = 443;
const httpOptions = {
cert: fs.readFileSync(`/root/DONOTDELETE/genomesmart.com.cert`),
key: fs.readFileSync(`/root/DONOTDELETE/genomesmart.com.key`)
};
app.use(compression());
var server = https.createServer(httpOptions, app);
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/browser/');
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/browser'));
app.get('*', function (req, res) {
res.setHeader("X-Frame-Options", "DENY");
res.sendFile('/dist/browser/index.html', { root: __dirname });
})
server.listen(PORT, function () {
console.log(`HTTPS server started listening on port: ${PORT}`);
});
http.createServer(function (req, res) {
res.writeHead(301, { 'Location': 'https://' + req.headers['host'] + req.url });
res.end();
}).listen(80);