Skip to content

Commit

Permalink
Merge pull request cirsfid-unibo#5 from StomCarlo/master
Browse files Browse the repository at this point in the history
added https protocol. Fixed cirsfid-unibo#1
  • Loading branch information
obujor authored Nov 6, 2017
2 parents b68af87 + 1157a98 commit edc294a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
8 changes: 7 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
{
"port": "9006"
"port": "9006",
"https":{
"enabled": false,
"key": "key.pem",
"certificate":"cert.pem",
"passPhrase":"passphrase"
}
}
28 changes: 24 additions & 4 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ function startParentProcess () {

function startChildProcess () {
var app = require('express')();

var config = require('./config.json');

// Middleware
app.use(require('express-domain-middleware'));
app.use(require('cors')());
Expand All @@ -81,10 +82,29 @@ function startChildProcess () {
// Error Handling
app.use(errorHandler);

// Start https server
if (config.https.enabled){
var https = require('https');
const fs = require('fs');

console.log("https: enabled");
const options = {
key: fs.readFileSync(config.https.key),
cert: fs.readFileSync(config.https.certificate),
passphrase: config.https.passPhrase
};
module.server = https.createServer(options, app).listen(config.port, function() {
console.log('Listening on port %d', module.server.address().port)
});

}
else{
// Start server
module.server = app.listen(require('./config.json').port, function() {
console.log('Listening on port %d', module.server.address().port);
});
module.server = app.listen(config.port, function() {
console.log('Listening on port %d', module.server.address().port)
});
}

}

function errorHandler (err, req, res, next) {
Expand Down

0 comments on commit edc294a

Please sign in to comment.