diff options
author | Egil Moeller <egil.moller@freecode.no> | 2012-07-03 23:30:40 +0200 |
---|---|---|
committer | Egil Moeller <egil.moller@freecode.no> | 2012-07-03 23:31:44 +0200 |
commit | b438a278a16fbac3b38ad2105c3431b7e669df83 (patch) | |
tree | 5fdff1cc0d84c0e082ba29d8e07804594e06afa4 /src/node/hooks | |
parent | 3338db9485b1e97818ba67a6008866cbce15fef0 (diff) | |
download | etherpad-lite-b438a278a16fbac3b38ad2105c3431b7e669df83.zip |
Make the server restart on plugin install
Diffstat (limited to 'src/node/hooks')
-rw-r--r-- | src/node/hooks/express.js | 62 | ||||
-rw-r--r-- | src/node/hooks/express/webaccess.js | 11 |
2 files changed, 71 insertions, 2 deletions
diff --git a/src/node/hooks/express.js b/src/node/hooks/express.js new file mode 100644 index 00000000..c7897e77 --- /dev/null +++ b/src/node/hooks/express.js @@ -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); +}
\ No newline at end of file diff --git a/src/node/hooks/express/webaccess.js b/src/node/hooks/express/webaccess.js index 028d8ab1..ffced047 100644 --- a/src/node/hooks/express/webaccess.js +++ b/src/node/hooks/express/webaccess.js @@ -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. @@ -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); } |