heroku
This commit is contained in:
parent
b02361bb30
commit
f97d830450
1 changed files with 50 additions and 50 deletions
100
index.js
100
index.js
|
|
@ -1,61 +1,61 @@
|
||||||
//NOTE: SERVER CONFIGURATION has 2 options. ENABLE 1 of 2 options
|
//NOTE: SERVER CONFIGURATION has 2 options. ENABLE 1 of 2 options
|
||||||
|
|
||||||
//NOTE: option (1) - https server (443) + redirection 80 to 443
|
// //NOTE: option (1) - https server (443) + redirection 80 to 443
|
||||||
|
//
|
||||||
//prepare credentials & etc
|
// //prepare credentials & etc
|
||||||
var fs = require('fs');
|
// var fs = require('fs');
|
||||||
var https = require('https');
|
// var https = require('https');
|
||||||
var privateKey = fs.readFileSync('/etc/letsencrypt/live/choir.run/privkey.pem', 'utf8');
|
// var privateKey = fs.readFileSync('/etc/letsencrypt/live/choir.run/privkey.pem', 'utf8');
|
||||||
var certificate = fs.readFileSync('/etc/letsencrypt/live/choir.run/fullchain.pem', 'utf8');
|
// var certificate = fs.readFileSync('/etc/letsencrypt/live/choir.run/fullchain.pem', 'utf8');
|
||||||
var credentials = {
|
// var credentials = {
|
||||||
key: privateKey,
|
// key: privateKey,
|
||||||
cert: certificate
|
// cert: certificate
|
||||||
};
|
// };
|
||||||
|
//
|
||||||
//https WWW server @ port 443
|
// //https WWW server @ port 443
|
||||||
var express = require('express');
|
|
||||||
var app = express();
|
|
||||||
var httpsWebServer = https.createServer(credentials, app).listen(443, function() {
|
|
||||||
console.log('[express] listening on *:443');
|
|
||||||
});
|
|
||||||
|
|
||||||
//http Redirection server @ port 80
|
|
||||||
// ==> Don't get why this works.. all others not. ==> https://stackoverflow.com/a/23283173
|
|
||||||
var http = require('http');
|
|
||||||
var httpApp = express();
|
|
||||||
var httpRouter = express.Router();
|
|
||||||
httpApp.use('*', httpRouter);
|
|
||||||
httpRouter.get('*', function(req, res) {
|
|
||||||
var host = req.get('Host');
|
|
||||||
// replace the port in the host
|
|
||||||
host = host.replace(/:\d+$/, ":" + app.get('port'));
|
|
||||||
// determine the redirect destination
|
|
||||||
var destination = ['https://', host, req.url].join('');
|
|
||||||
return res.redirect(destination);
|
|
||||||
});
|
|
||||||
var httpServer = http.createServer(httpApp);
|
|
||||||
httpServer.listen(80);
|
|
||||||
|
|
||||||
//https socket.io server @ port 443 (same port as WWW service)
|
|
||||||
var io = require('socket.io')(httpsWebServer, {
|
|
||||||
'pingInterval': 1000,
|
|
||||||
'pingTimeout': 3000
|
|
||||||
});
|
|
||||||
|
|
||||||
// //NOTE: option (2) - simple http dev server (8080)
|
|
||||||
|
|
||||||
// var http = require('http');
|
|
||||||
// var express = require('express');
|
// var express = require('express');
|
||||||
// var app = express();
|
// var app = express();
|
||||||
// var httpServer = http.createServer(app);
|
// var httpsWebServer = https.createServer(credentials, app).listen(443, function() {
|
||||||
// httpServer.listen(8080);
|
// console.log('[express] listening on *:443');
|
||||||
|
// });
|
||||||
// //http socket.io server @ port 8080 (same port as WWW service)
|
//
|
||||||
// var io = require('socket.io')(httpServer, {
|
// //http Redirection server @ port 80
|
||||||
|
// // ==> Don't get why this works.. all others not. ==> https://stackoverflow.com/a/23283173
|
||||||
|
// var http = require('http');
|
||||||
|
// var httpApp = express();
|
||||||
|
// var httpRouter = express.Router();
|
||||||
|
// httpApp.use('*', httpRouter);
|
||||||
|
// httpRouter.get('*', function(req, res) {
|
||||||
|
// var host = req.get('Host');
|
||||||
|
// // replace the port in the host
|
||||||
|
// host = host.replace(/:\d+$/, ":" + app.get('port'));
|
||||||
|
// // determine the redirect destination
|
||||||
|
// var destination = ['https://', host, req.url].join('');
|
||||||
|
// return res.redirect(destination);
|
||||||
|
// });
|
||||||
|
// var httpServer = http.createServer(httpApp);
|
||||||
|
// httpServer.listen(80);
|
||||||
|
//
|
||||||
|
// //https socket.io server @ port 443 (same port as WWW service)
|
||||||
|
// var io = require('socket.io')(httpsWebServer, {
|
||||||
// 'pingInterval': 1000,
|
// 'pingInterval': 1000,
|
||||||
// 'pingTimeout': 3000
|
// 'pingTimeout': 3000
|
||||||
// });
|
// });
|
||||||
|
|
||||||
|
//NOTE: option (2) - simple http dev server (8080)
|
||||||
|
|
||||||
|
var http = require('http');
|
||||||
|
var express = require('express');
|
||||||
|
var app = express();
|
||||||
|
var httpServer = http.createServer(app);
|
||||||
|
httpServer.listen(process.env.PORT || 8080);
|
||||||
|
|
||||||
|
//http socket.io server @ port 8080 (same port as WWW service)
|
||||||
|
var io = require('socket.io')(httpServer, {
|
||||||
|
'pingInterval': 1000,
|
||||||
|
'pingTimeout': 3000
|
||||||
|
});
|
||||||
|
|
||||||
//express configuration
|
//express configuration
|
||||||
app.use(express.static('public'));
|
app.use(express.static('public'));
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue