-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
39 lines (33 loc) · 1.01 KB
/
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
37
38
39
"use strict";
var express = require('express');
var app = express();
var http = require('http').Server(app);
var fs = require('fs');
var privateKey = fs.readFileSync('/root/private.pem', 'utf8');
var certificate = fs.readFileSync('/root/file.crt', 'utf8');
var credentials = {key: privateKey, cert: certificate};
var https = require('https').createServer(credentials, app);
var io = require('socket.io')(https);
var sf = require(__dirname+'/socketFunc.js');
var g = require(__dirname+'/global.js');
var pages = g.pages;
http.listen(80, () => {
console.log(new Date().toLocaleString() + ' listening on *:80');
});
https.listen(443, () => {
console.log(new Date().toLocaleString() + ' listening on *:443');
});
app.get('/', function(req, res) {
console.log(req.hostname, req.protocol);
if(req.protocol === "http"){
res.writeHead(301,{
'Location': `https://${req.hostname}/`
});
res.end();
}
else {
res.send(pages[0]);
}
});
app.use(express.static(__dirname + '/public'));
io.on('connection',sf);