-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
36 lines (27 loc) · 914 Bytes
/
server.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
var fs = require('fs');
var path = require('path');
var http = require('http');
var https = require('https');
var privateKey = fs.readFileSync('server/sertificate/key.txt');
var certificate = fs.readFileSync('server/sertificate/mainCert.pfx');
const NODE_ENV = process.env.NODE_ENV || 'development';
console.log('Node env %s', NODE_ENV);
var options = {
pfx: certificate,
passphrase: 'aprix'
};
var express = require('express');
var app = express();
app.use(express.static('client'));
app.get('/', function (req, res) {
res.sendFile(path.join(__dirname + '/client/index.html'));
})
var redirectApp = express();
redirectApp.get('/*', function (req, res) {
res.redirect('https://' + req.hostname);
})
var httpServer = http.createServer(redirectApp);
var httpsServer = https.createServer(options, app);
require('./server_socket')(httpsServer);
httpServer.listen(80);
httpsServer.listen(443);