Skip to content

Commit

Permalink
run on https only with certs and production env
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhamqweasd committed Nov 13, 2017
1 parent ed2b33b commit a2b89b5
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ require('winston-loggly');
var slack = require('winston-bishop-slack').Slack;
var util = require('util');

var CLOUDBOOST_HOSTED = process.env["CLOUDBOOST_HOSTED"]
console.log('IS CLOUDBOOST RUNNING ON AN HOSTED ENV - ' , CLOUDBOOST_HOSTED)

global.keys = require('./database-connect/keys.js')();

if (global.env === "development") {
Expand Down Expand Up @@ -82,7 +85,7 @@ var https = null;
try {
if (fs.statSync('./config/cert.crt').isFile() && fs.statSync('./config/key.key').isFile()) {
//use https
console.log("Running on HTTPS protocol.");
console.log("Found HTTPS Certs, adding to https server.");
var httpsOptions = {
key: fs.readFileSync('./config/key.key'),
cert: fs.readFileSync('./config/cert.crt')
Expand All @@ -100,7 +103,8 @@ http = require('http').createServer(global.app);
require('./database-connect/cors.js')(); //cors!
var io = require('socket.io')();

if (https) {
// attach io to https only if running in hosted env and certs are found
if (https && CLOUDBOOST_HOSTED) {
io.attach(https);
} else {
io.attach(http);
Expand Down Expand Up @@ -490,7 +494,8 @@ http.listen(app.get('port'), function() {
}
});

if (https) {
// run https only if running in hosted env and certs are found
if (https && CLOUDBOOST_HOSTED) {
https.listen(4731, function() {
console.log("HTTPS Server started.");
});
Expand Down

0 comments on commit a2b89b5

Please sign in to comment.