Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 1148 add native node https support #1202

Merged
merged 3 commits into from
Nov 25, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ src/static/js/jquery.js
npm-debug.log
*.DS_Store
.ep_initialized
*.crt
*.key
18 changes: 16 additions & 2 deletions settings.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,24 @@
// alternatively, set up a fully specified Url to your own favicon
"favicon": "favicon.ico",

//Ip and port which etherpad should bind at
//IP and port which etherpad should bind at
"ip": "0.0.0.0",
"port" : 9001,


/*
// Node native SSL support
// this is disabled by default
//
// make sure to have the minimum and correct file access permissions set
// so that the Etherpad server can access them

"ssl" : {
"key" : "/path-to-your/epl-server.key",
"cert" : "/path-to-your/epl-server.crt"
},

*/

//The Type of the database. You can choose between dirty, postgres, sqlite and mysql
//You shouldn't use "dirty" for for anything else than testing or development
"dbType" : "dirty",
Expand Down
24 changes: 22 additions & 2 deletions src/node/hooks/express.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks");
var http = require('http');
var express = require('express');
var settings = require('../utils/Settings');
var fs = require('fs');
Expand Down Expand Up @@ -50,7 +49,28 @@ exports.restartServer = function () {
}

var app = express(); // New syntax for express v3
server = http.createServer(app);

if (settings.ssl) {

console.log( "SSL -- enabled");
console.log( "SSL -- server key file: " + settings.ssl.key );
console.log( "SSL -- Certificate Authority's certificate file: " + settings.ssl.cert );

options = {
key: fs.readFileSync( settings.ssl.key ),
cert: fs.readFileSync( settings.ssl.cert )
};

var https = require('https');
server = https.createServer(options, app);

} else {

console.log( "SSL -- not enabled!" );

var http = require('http');
server = http.createServer(app);
}

app.use(function (req, res, next) {
res.header("Server", serverName);
Expand Down
7 changes: 7 additions & 0 deletions src/node/utils/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ exports.ip = "0.0.0.0";
* The Port ep-lite should listen to
*/
exports.port = process.env.PORT || 9001;

/**
* The SSL signed server key and the Certificate Authority's own certificate
* default case: ep-lite does *not* use SSL. A signed server key is not required in this case.
*/
exports.ssl = false;

/*
* The Type of the database
*/
Expand Down