-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserver.js
46 lines (36 loc) · 1.25 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
40
41
42
43
44
45
46
'use strict';
const fs = require('fs');
const http = require('http');
const https = require('https');
const express = require('express');
const app = express();
const _ = require('lodash')
const favicon = require('serve-favicon');
const path = require('path')
const startSockets = require('./sockLogic.js');
let env = process.env.NODE_ENV = process.env.NODE_ENV || 'development';
let httpPort = process.env.PORT || 8000;
// let httpsPort = process.env.PORT || 1337;
let server = http.createServer(app).listen(httpPort, function(){
console.log('Listening on ' + httpPort)
});
// const options = {
// key: fs.readFileSync('server.key'),
// cert: fs.readFileSync('server.crt')
// };
// const server = https.createServer(options, app).listen(port, function(){
// console.log('Listening on ' + port)
// });
app.use((req, res, next) => {
if (req.headers['x-forwarded-proto'] === 'http') {
res.redirect('https://' + req.hostname + req.url);
} else {
next();
}
});
app.use('/', express.static(path.join(__dirname, "public")));
app.use(favicon(path.join(__dirname,'public','favicon.ico')));
// let httpsServer = https.createServer(options, app).listen(httpsPort, function(){
// console.log('Also listening on ' + httpsPort)
// });
startSockets(server);