forked from team-genjutsu/miragejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
executable file
·48 lines (36 loc) · 1.36 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
47
48
'use strict';
const fs = require('fs');
const http = require('http');
const https = require('https');
const express = require('express');
const app = express();
const favicon = require('serve-favicon');
const path = require('path');
const mirageSockets = require('./mirageSockets.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(__dirname + '/server_cert/server.key'),
cert: fs.readFileSync(__dirname + '/server_cert/server.crt')
};
// const server = https.createServer(options, app).listen(port, function(){
// console.log('Listening on ' + port)
// });
// redirects all incoming requests from http protocol to https equivalent
// 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);
// });
mirageSockets(server);