Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/Pita/etherpad-lite into …
Browse files Browse the repository at this point in the history
…develop
  • Loading branch information
JohnMcLear committed Jul 5, 2012
2 parents d561354 + d59956b commit 9bfd576
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 47 deletions.
4 changes: 4 additions & 0 deletions src/ep.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"parts": [
{ "name": "express", "hooks": {
"createServer": "ep_etherpad-lite/node/hooks/express:createServer",
"restartServer": "ep_etherpad-lite/node/hooks/express:restartServer"
} },
{ "name": "static", "hooks": { "expressCreateServer": "ep_etherpad-lite/node/hooks/express/static:expressCreateServer" } },
{ "name": "specialpages", "hooks": { "expressCreateServer": "ep_etherpad-lite/node/hooks/express/specialpages:expressCreateServer" } },
{ "name": "padurlsanitize", "hooks": { "expressCreateServer": "ep_etherpad-lite/node/hooks/express/padurlsanitize:expressCreateServer" } },
Expand Down
62 changes: 62 additions & 0 deletions src/node/hooks/express.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
var hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks");
var express = require('express');
var settings = require('../utils/Settings');
var fs = require('fs');
var path = require('path');
var _ = require("underscore");

var server;
var serverName;

exports.createServer = function () {
//try to get the git version
var version = "";
try
{
var rootPath = path.resolve(npm.dir, '..');
var ref = fs.readFileSync(rootPath + "/.git/HEAD", "utf-8");
var refPath = rootPath + "/.git/" + ref.substring(5, ref.indexOf("\n"));
version = fs.readFileSync(refPath, "utf-8");
version = version.substring(0, 7);
console.log("Your Etherpad Lite git version is " + version);
}
catch(e)
{
console.warn("Can't get git version for server header\n" + e.message)
}
console.log("Report bugs at https://github.com/Pita/etherpad-lite/issues")

serverName = "Etherpad-Lite " + version + " (http://j.mp/ep-lite)";

exports.restartServer();

console.log("You can access your Etherpad-Lite instance at http://" + settings.ip + ":" + settings.port + "/");
if(!_.isEmpty(settings.users)){
console.log("The plugin admin page is at http://" + settings.ip + ":" + settings.port + "/admin/plugins");
}
else{
console.warn("Admin username and password not set in settings.json. To access admin please uncomment and edit 'users' in settings.json");
}

}

exports.restartServer = function () {
if (server) {
console.log("Restarting express server");
server.close();
}

server = express.createServer();

server.use(function (req, res, next) {
res.header("Server", serverName);
next();
});

server.configure(function() {
hooks.callAll("expressConfigure", {"app": server});
});
hooks.callAll("expressCreateServer", {"app": server});

server.listen(settings.port, settings.ip);
}
11 changes: 9 additions & 2 deletions src/node/hooks/express/webaccess.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ exports.basicAuth = function (req, res, next) {
});
}

var secret = null;

exports.expressConfigure = function (hook_name, args, cb) {
// If the log level specified in the config file is WARN or ERROR the application server never starts listening to requests as reported in issue #158.
// Not installing the log4js connect logger when the log level has a higher severity than INFO since it would not log at that level anyway.
Expand All @@ -100,10 +102,15 @@ exports.expressConfigure = function (hook_name, args, cb) {
* name) to a javascript identifier compatible string. Makes code
* handling it cleaner :) */

args.app.sessionStore = new express.session.MemoryStore();
if (!exports.sessionStore) {
exports.sessionStore = new express.session.MemoryStore();
secret = randomString(32);
}

args.app.sessionStore = exports.sessionStore;
args.app.use(express.session({store: args.app.sessionStore,
key: 'express_sid',
secret: apikey = randomString(32)}));
secret: secret}));

args.app.use(exports.basicAuth);
}
45 changes: 1 addition & 44 deletions src/node/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,13 @@
*/

var log4js = require('log4js');
var fs = require('fs');
var settings = require('./utils/Settings');
var db = require('./db/DB');
var async = require('async');
var express = require('express');
var path = require('path');
var plugins = require("ep_etherpad-lite/static/js/pluginfw/plugins");
var hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks");
var npm = require("npm/lib/npm.js");
var _ = require("underscore");

//try to get the git version
var version = "";
try
{
var rootPath = path.resolve(npm.dir, '..');
var ref = fs.readFileSync(rootPath + "/.git/HEAD", "utf-8");
var refPath = rootPath + "/.git/" + ref.substring(5, ref.indexOf("\n"));
version = fs.readFileSync(refPath, "utf-8");
version = version.substring(0, 7);
console.log("Your Etherpad Lite git version is " + version);
}
catch(e)
{
console.warn("Can't get git version for server header\n" + e.message)
}

console.log("Report bugs at https://github.com/Pita/etherpad-lite/issues")

var serverName = "Etherpad-Lite " + version + " (http://j.mp/ep-lite)";

//set loglevel
log4js.setGlobalLogLevel(settings.loglevel);
Expand All @@ -75,27 +52,7 @@ async.waterfall([
//initalize the http server
function (callback)
{
//create server
var app = express.createServer();

app.use(function (req, res, next) {
res.header("Server", serverName);
next();
});

app.configure(function() { hooks.callAll("expressConfigure", {"app": app}); });

hooks.callAll("expressCreateServer", {"app": app});

//let the server listen
app.listen(settings.port, settings.ip);
console.log("You can access your Etherpad-Lite instance at http://" + settings.ip + ":" + settings.port + "/");
if(!_.isEmpty(settings.users)){
console.log("The plugin admin page is at http://" + settings.ip + ":" + settings.port + "/admin/plugins");
}
else{
console.warn("Admin username and password not set in settings.json. To access admin please uncomment and edit 'users' in settings.json");
}
hooks.callAll("createServer", {});
callback(null);
}
]);
10 changes: 9 additions & 1 deletion src/static/js/pluginfw/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks");
var npm = require("npm");
var registry = require("npm/lib/utils/npm-registry-client/index.js");

var withNpm = function (npmfn, cb) {
var withNpm = function (npmfn, final, cb) {
npm.load({}, function (er) {
if (er) return cb({progress:1, error:er});
npm.on("log", function (message) {
Expand All @@ -15,6 +15,7 @@ var withNpm = function (npmfn, cb) {
data.progress = 1;
data.message = "Done.";
cb(data);
final();
});
});
}
Expand All @@ -36,6 +37,9 @@ exports.uninstall = function(plugin_name, cb) {
});
});
},
function () {
hooks.aCallAll("restartServer", {}, function () {});
},
cb
);
};
Expand All @@ -51,6 +55,9 @@ exports.install = function(plugin_name, cb) {
});
});
},
function () {
hooks.aCallAll("restartServer", {}, function () {});
},
cb
);
};
Expand Down Expand Up @@ -93,6 +100,7 @@ exports.search = function(query, cache, cb) {
}
);
},
function () { },
cb
);
};

0 comments on commit 9bfd576

Please sign in to comment.