summaryrefslogtreecommitdiff
path: root/src/node/hooks
diff options
context:
space:
mode:
authorJohn McLear <john@mclear.co.uk>2015-04-11 00:13:45 +0100
committerJohn McLear <john@mclear.co.uk>2015-04-11 00:13:45 +0100
commit402e53d88e2a80c436d4ec93371e4fd14919d0a5 (patch)
treea2d4bb22f440a7ea92898367fda65f6f28cb3dc9 /src/node/hooks
parent7cb12ac10cc4470cadfbab883715c3d67d7c2e41 (diff)
parentfd1d285a77db1c583be3e42fb1929ecd4dd41633 (diff)
downloadetherpad-lite-402e53d88e2a80c436d4ec93371e4fd14919d0a5.zip
Merge pull request #2584 from devoidfury/express4
Express 4 support
Diffstat (limited to 'src/node/hooks')
-rw-r--r--src/node/hooks/express.js6
-rw-r--r--src/node/hooks/express/errorhandling.js4
-rw-r--r--src/node/hooks/express/padreadonly.js2
-rw-r--r--src/node/hooks/express/padurlsanitize.js4
-rw-r--r--src/node/hooks/express/socketio.js9
-rw-r--r--src/node/hooks/express/specialpages.js8
-rw-r--r--src/node/hooks/express/static.js5
-rw-r--r--src/node/hooks/express/tests.js2
-rw-r--r--src/node/hooks/express/webaccess.js10
-rw-r--r--src/node/hooks/i18n.js2
10 files changed, 26 insertions, 26 deletions
diff --git a/src/node/hooks/express.js b/src/node/hooks/express.js
index bf849419..3abe41f8 100644
--- a/src/node/hooks/express.js
+++ b/src/node/hooks/express.js
@@ -69,10 +69,8 @@ exports.restartServer = function () {
if(settings.trustProxy){
app.enable('trust proxy');
}
-
- app.configure(function() {
- hooks.callAll("expressConfigure", {"app": app});
- });
+
+ hooks.callAll("expressConfigure", {"app": app});
hooks.callAll("expressCreateServer", {"app": app, "server": server});
server.listen(settings.port, settings.ip);
diff --git a/src/node/hooks/express/errorhandling.js b/src/node/hooks/express/errorhandling.js
index 087dd50e..7afe80ae 100644
--- a/src/node/hooks/express/errorhandling.js
+++ b/src/node/hooks/express/errorhandling.js
@@ -39,7 +39,7 @@ exports.expressCreateServer = function (hook_name, args, cb) {
// if an error occurs Connect will pass it down
// through these "error-handling" middleware
// allowing you to respond however you like
- res.send(500, { error: 'Sorry, something bad happened!' });
+ res.status(500).send({ error: 'Sorry, something bad happened!' });
console.error(err.stack? err.stack : err.toString());
stats.meter('http500').mark()
})
@@ -50,4 +50,4 @@ exports.expressCreateServer = function (hook_name, args, cb) {
//https://github.com/joyent/node/issues/1553
process.on('SIGINT', exports.gracefulShutdown);
}
-} \ No newline at end of file
+}
diff --git a/src/node/hooks/express/padreadonly.js b/src/node/hooks/express/padreadonly.js
index d60d3863..66be3339 100644
--- a/src/node/hooks/express/padreadonly.js
+++ b/src/node/hooks/express/padreadonly.js
@@ -55,7 +55,7 @@ exports.expressCreateServer = function (hook_name, args, cb) {
ERR(err);
if(err == "notfound")
- res.send(404, '404 - Not Found');
+ res.status(404).send('404 - Not Found');
else
res.send(html);
});
diff --git a/src/node/hooks/express/padurlsanitize.js b/src/node/hooks/express/padurlsanitize.js
index 2aadccdc..94cbe36a 100644
--- a/src/node/hooks/express/padurlsanitize.js
+++ b/src/node/hooks/express/padurlsanitize.js
@@ -7,7 +7,7 @@ exports.expressCreateServer = function (hook_name, args, cb) {
//ensure the padname is valid and the url doesn't end with a /
if(!padManager.isValidPadId(padId) || /\/$/.test(req.url))
{
- res.send(404, 'Such a padname is forbidden');
+ res.status(404).send('Such a padname is forbidden');
}
else
{
@@ -19,7 +19,7 @@ exports.expressCreateServer = function (hook_name, args, cb) {
var query = url.parse(req.url).query;
if ( query ) real_url += '?' + query;
res.header('Location', real_url);
- res.send(302, 'You should be redirected to <a href="' + real_url + '">' + real_url + '</a>');
+ res.status(302).send('You should be redirected to <a href="' + real_url + '">' + real_url + '</a>');
}
//the pad id was fine, so just render it
else
diff --git a/src/node/hooks/express/socketio.js b/src/node/hooks/express/socketio.js
index 35d6d074..23622f3a 100644
--- a/src/node/hooks/express/socketio.js
+++ b/src/node/hooks/express/socketio.js
@@ -6,7 +6,8 @@ var webaccess = require("ep_etherpad-lite/node/hooks/express/webaccess");
var padMessageHandler = require("../../handler/PadMessageHandler");
-var connect = require('connect');
+var cookieParser = require('cookie-parser');
+var sessionModule = require('express-session');
exports.expressCreateServer = function (hook_name, args, cb) {
//init socket.io and redirect all requests to the MessageHandler
@@ -20,6 +21,7 @@ exports.expressCreateServer = function (hook_name, args, cb) {
/* Require an express session cookie to be present, and load the
* session. See http://www.danielbaulig.de/socket-ioexpress for more
* info */
+ var cookieParserFn = cookieParser(webaccess.secret, {});
io.use(function(socket, accept) {
var data = socket.request;
@@ -29,8 +31,7 @@ exports.expressCreateServer = function (hook_name, args, cb) {
}else{
if (!data.headers.cookie) return accept('No session cookie transmitted.', false);
}
- // Use connect's cookie parser, because it knows how to parse signed cookies
- connect.cookieParser(webaccess.secret)(data, {}, function(err){
+ cookieParserFn(data, {}, function(err){
if(err) {
console.error(err);
accept("Couldn't parse request cookies. ", false);
@@ -40,7 +41,7 @@ exports.expressCreateServer = function (hook_name, args, cb) {
data.sessionID = data.signedCookies.express_sid;
args.app.sessionStore.get(data.sessionID, function (err, session) {
if (err || !session) return accept('Bad session / session has expired', false);
- data.session = new connect.middleware.session.Session(data, session);
+ data.session = new sessionModule.Session(data, session);
accept(null, true);
});
});
diff --git a/src/node/hooks/express/specialpages.js b/src/node/hooks/express/specialpages.js
index 063328fb..0370c4fc 100644
--- a/src/node/hooks/express/specialpages.js
+++ b/src/node/hooks/express/specialpages.js
@@ -19,13 +19,13 @@ exports.expressCreateServer = function (hook_name, args, cb) {
args.app.get('/robots.txt', function(req, res)
{
var filePath = path.normalize(__dirname + "/../../../static/custom/robots.txt");
- res.sendfile(filePath, function(err)
+ res.sendFile(filePath, function(err)
{
//there is no custom favicon, send the default robots.txt which dissallows all
if(err)
{
filePath = path.normalize(__dirname + "/../../../static/robots.txt");
- res.sendfile(filePath);
+ res.sendFile(filePath);
}
});
});
@@ -60,13 +60,13 @@ exports.expressCreateServer = function (hook_name, args, cb) {
args.app.get( /\/favicon.ico$/, function(req, res)
{
var filePath = path.normalize(__dirname + "/../../../static/custom/favicon.ico");
- res.sendfile(filePath, function(err)
+ res.sendFile(filePath, function(err)
{
//there is no custom favicon, send the default favicon
if(err)
{
filePath = path.normalize(__dirname + "/../../../static/favicon.ico");
- res.sendfile(filePath);
+ res.sendFile(filePath);
}
});
});
diff --git a/src/node/hooks/express/static.js b/src/node/hooks/express/static.js
index e5a2bff0..7af54b5d 100644
--- a/src/node/hooks/express/static.js
+++ b/src/node/hooks/express/static.js
@@ -9,7 +9,7 @@ exports.expressCreateServer = function (hook_name, args, cb) {
// Cache both minified and static.
var assetCache = new CachingMiddleware;
- args.app.all('/(javascripts|static)/*', assetCache.handle);
+ args.app.all(/\/(javascripts|static)\/(.*)/, assetCache.handle);
// Minify will serve static files compressed (minify enabled). It also has
// file-specific hacks for ace/require-kernel/etc.
@@ -30,7 +30,8 @@ exports.expressCreateServer = function (hook_name, args, cb) {
Yajsml.associators.associationsForSimpleMapping(minify.tar);
var associator = new StaticAssociator(associations);
jsServer.setAssociator(associator);
- args.app.use(jsServer);
+
+ args.app.use(jsServer.handle.bind(jsServer));
// serve plugin definitions
// not very static, but served here so that client can do require("pluginfw/static/js/plugin-definitions.js");
diff --git a/src/node/hooks/express/tests.js b/src/node/hooks/express/tests.js
index 3157d68e..fcd81381 100644
--- a/src/node/hooks/express/tests.js
+++ b/src/node/hooks/express/tests.js
@@ -50,7 +50,7 @@ exports.expressCreateServer = function (hook_name, args, cb) {
args.app.get('/tests/frontend/*', function (req, res) {
var filePath = url2FilePath(req.url);
- res.sendfile(filePath);
+ res.sendFile(filePath);
});
args.app.get('/tests/frontend', function (req, res) {
diff --git a/src/node/hooks/express/webaccess.js b/src/node/hooks/express/webaccess.js
index b798f2c7..cb5a2207 100644
--- a/src/node/hooks/express/webaccess.js
+++ b/src/node/hooks/express/webaccess.js
@@ -4,7 +4,8 @@ var httpLogger = log4js.getLogger("http");
var settings = require('../../utils/Settings');
var hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks');
var ueberStore = require('../../db/SessionStore');
-var stats = require('ep_etherpad-lite/node/stats')
+var stats = require('ep_etherpad-lite/node/stats');
+var sessionModule = require('express-session');
//checks for basic http auth
exports.basicAuth = function (req, res, next) {
@@ -56,10 +57,10 @@ exports.basicAuth = function (req, res, next) {
res.header('WWW-Authenticate', 'Basic realm="Protected Area"');
if (req.headers.authorization) {
setTimeout(function () {
- res.send(401, 'Authentication required');
+ res.status(401).send('Authentication required');
}, 1000);
} else {
- res.send(401, 'Authentication required');
+ res.status(401).send('Authentication required');
}
}));
}
@@ -117,9 +118,8 @@ exports.expressConfigure = function (hook_name, args, cb) {
exports.secret = settings.sessionKey; // Isn't this being reset each time the server spawns?
}
- args.app.use(express.cookieParser(exports.secret));
args.app.sessionStore = exports.sessionStore;
- args.app.use(express.session({secret: exports.secret, store: args.app.sessionStore, key: 'express_sid' }));
+ args.app.use(sessionModule({secret: exports.secret, store: args.app.sessionStore, resave: true, saveUninitialized: true, name: 'express_sid' }));
args.app.use(exports.basicAuth);
}
diff --git a/src/node/hooks/i18n.js b/src/node/hooks/i18n.js
index 67815659..1d28b544 100644
--- a/src/node/hooks/i18n.js
+++ b/src/node/hooks/i18n.js
@@ -91,7 +91,7 @@ exports.expressCreateServer = function(n, args) {
res.setHeader('Content-Type', 'application/json; charset=utf-8');
res.send('{"'+locale+'":'+JSON.stringify(locales[locale])+'}');
} else {
- res.send(404, 'Language not available');
+ res.status(404).send('Language not available');
}
})