update for express 4.x
This commit is contained in:
parent
7b86eb09bc
commit
d0b39c01fb
|
@ -4,7 +4,7 @@
|
||||||
* This is not used for authors that are created via the API at current
|
* This is not used for authors that are created via the API at current
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var Store = require('ep_etherpad-lite/node_modules/connect/lib/middleware/session/store'),
|
var Store = require('ep_etherpad-lite/node_modules/express-session').Store,
|
||||||
db = require('ep_etherpad-lite/node/db/DB').db,
|
db = require('ep_etherpad-lite/node/db/DB').db,
|
||||||
log4js = require('ep_etherpad-lite/node_modules/log4js'),
|
log4js = require('ep_etherpad-lite/node_modules/log4js'),
|
||||||
messageLogger = log4js.getLogger("SessionStore");
|
messageLogger = log4js.getLogger("SessionStore");
|
||||||
|
|
|
@ -103,7 +103,7 @@ exports.doExport = function(req, res, padId, type)
|
||||||
//send the file
|
//send the file
|
||||||
function(callback)
|
function(callback)
|
||||||
{
|
{
|
||||||
res.sendfile(destFile, null, callback);
|
res.sendFile(destFile, null, callback);
|
||||||
},
|
},
|
||||||
//clean up temporary files
|
//clean up temporary files
|
||||||
function(callback)
|
function(callback)
|
||||||
|
@ -184,7 +184,7 @@ exports.doExport = function(req, res, padId, type)
|
||||||
//send the file
|
//send the file
|
||||||
function(callback)
|
function(callback)
|
||||||
{
|
{
|
||||||
res.sendfile(destFile, null, callback);
|
res.sendFile(destFile, null, callback);
|
||||||
},
|
},
|
||||||
//clean up temporary files
|
//clean up temporary files
|
||||||
function(callback)
|
function(callback)
|
||||||
|
|
|
@ -67,10 +67,8 @@ exports.restartServer = function () {
|
||||||
if(settings.trustProxy){
|
if(settings.trustProxy){
|
||||||
app.enable('trust proxy');
|
app.enable('trust proxy');
|
||||||
}
|
}
|
||||||
|
|
||||||
app.configure(function() {
|
hooks.callAll("expressConfigure", {"app": app});
|
||||||
hooks.callAll("expressConfigure", {"app": app});
|
|
||||||
});
|
|
||||||
hooks.callAll("expressCreateServer", {"app": app, "server": server});
|
hooks.callAll("expressCreateServer", {"app": app, "server": server});
|
||||||
|
|
||||||
server.listen(settings.port, settings.ip);
|
server.listen(settings.port, settings.ip);
|
||||||
|
|
|
@ -6,7 +6,8 @@ var webaccess = require("ep_etherpad-lite/node/hooks/express/webaccess");
|
||||||
|
|
||||||
var padMessageHandler = require("../../handler/PadMessageHandler");
|
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) {
|
exports.expressCreateServer = function (hook_name, args, cb) {
|
||||||
//init socket.io and redirect all requests to the MessageHandler
|
//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
|
/* Require an express session cookie to be present, and load the
|
||||||
* session. See http://www.danielbaulig.de/socket-ioexpress for more
|
* session. See http://www.danielbaulig.de/socket-ioexpress for more
|
||||||
* info */
|
* info */
|
||||||
|
var cookieParserFn = cookieParser(webaccess.secret, {});
|
||||||
|
|
||||||
io.use(function(socket, accept) {
|
io.use(function(socket, accept) {
|
||||||
var data = socket.request;
|
var data = socket.request;
|
||||||
|
@ -29,8 +31,7 @@ exports.expressCreateServer = function (hook_name, args, cb) {
|
||||||
}else{
|
}else{
|
||||||
if (!data.headers.cookie) return accept('No session cookie transmitted.', false);
|
if (!data.headers.cookie) return accept('No session cookie transmitted.', false);
|
||||||
}
|
}
|
||||||
// Use connect's cookie parser, because it knows how to parse signed cookies
|
cookieParserFn(data, {}, function(err){
|
||||||
connect.cookieParser(webaccess.secret)(data, {}, function(err){
|
|
||||||
if(err) {
|
if(err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
accept("Couldn't parse request cookies. ", false);
|
accept("Couldn't parse request cookies. ", false);
|
||||||
|
@ -40,7 +41,7 @@ exports.expressCreateServer = function (hook_name, args, cb) {
|
||||||
data.sessionID = data.signedCookies.express_sid;
|
data.sessionID = data.signedCookies.express_sid;
|
||||||
args.app.sessionStore.get(data.sessionID, function (err, session) {
|
args.app.sessionStore.get(data.sessionID, function (err, session) {
|
||||||
if (err || !session) return accept('Bad session / session has expired', false);
|
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);
|
accept(null, true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -19,13 +19,13 @@ exports.expressCreateServer = function (hook_name, args, cb) {
|
||||||
args.app.get('/robots.txt', function(req, res)
|
args.app.get('/robots.txt', function(req, res)
|
||||||
{
|
{
|
||||||
var filePath = path.normalize(__dirname + "/../../../static/custom/robots.txt");
|
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
|
//there is no custom favicon, send the default robots.txt which dissallows all
|
||||||
if(err)
|
if(err)
|
||||||
{
|
{
|
||||||
filePath = path.normalize(__dirname + "/../../../static/robots.txt");
|
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)
|
args.app.get( /\/favicon.ico$/, function(req, res)
|
||||||
{
|
{
|
||||||
var filePath = path.normalize(__dirname + "/../../../static/custom/favicon.ico");
|
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
|
//there is no custom favicon, send the default favicon
|
||||||
if(err)
|
if(err)
|
||||||
{
|
{
|
||||||
filePath = path.normalize(__dirname + "/../../../static/favicon.ico");
|
filePath = path.normalize(__dirname + "/../../../static/favicon.ico");
|
||||||
res.sendfile(filePath);
|
res.sendFile(filePath);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -9,11 +9,11 @@ exports.expressCreateServer = function (hook_name, args, cb) {
|
||||||
|
|
||||||
// Cache both minified and static.
|
// Cache both minified and static.
|
||||||
var assetCache = new CachingMiddleware;
|
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
|
// Minify will serve static files compressed (minify enabled). It also has
|
||||||
// file-specific hacks for ace/require-kernel/etc.
|
// file-specific hacks for ace/require-kernel/etc.
|
||||||
args.app.all('/static/:filename(*)', minify.minify);
|
args.app.all('/static/:filename', minify.minify);
|
||||||
|
|
||||||
// Setup middleware that will package JavaScript files served by minify for
|
// Setup middleware that will package JavaScript files served by minify for
|
||||||
// CommonJS loader on the client-side.
|
// CommonJS loader on the client-side.
|
||||||
|
@ -30,7 +30,8 @@ exports.expressCreateServer = function (hook_name, args, cb) {
|
||||||
Yajsml.associators.associationsForSimpleMapping(minify.tar);
|
Yajsml.associators.associationsForSimpleMapping(minify.tar);
|
||||||
var associator = new StaticAssociator(associations);
|
var associator = new StaticAssociator(associations);
|
||||||
jsServer.setAssociator(associator);
|
jsServer.setAssociator(associator);
|
||||||
args.app.use(jsServer);
|
|
||||||
|
args.app.use(jsServer.handle.bind(jsServer));
|
||||||
|
|
||||||
// serve plugin definitions
|
// serve plugin definitions
|
||||||
// not very static, but served here so that client can do require("pluginfw/static/js/plugin-definitions.js");
|
// not very static, but served here so that client can do require("pluginfw/static/js/plugin-definitions.js");
|
||||||
|
|
|
@ -4,7 +4,8 @@ var httpLogger = log4js.getLogger("http");
|
||||||
var settings = require('../../utils/Settings');
|
var settings = require('../../utils/Settings');
|
||||||
var hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks');
|
var hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks');
|
||||||
var ueberStore = require('../../db/SessionStore');
|
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
|
//checks for basic http auth
|
||||||
exports.basicAuth = function (req, res, next) {
|
exports.basicAuth = function (req, res, next) {
|
||||||
|
@ -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?
|
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.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);
|
args.app.use(exports.basicAuth);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,9 +18,10 @@
|
||||||
"resolve" : "1.1.6",
|
"resolve" : "1.1.6",
|
||||||
"socket.io" : "1.3.5",
|
"socket.io" : "1.3.5",
|
||||||
"ueberDB" : "0.2.15",
|
"ueberDB" : "0.2.15",
|
||||||
"express" : "3.8.1",
|
"express" : "4.12.3",
|
||||||
|
"express-session" : "1.10.4",
|
||||||
|
"cookie-parser" : "1.3.4",
|
||||||
"async" : "0.9.0",
|
"async" : "0.9.0",
|
||||||
"connect" : "2.7.11",
|
|
||||||
"clean-css" : "3.1.9",
|
"clean-css" : "3.1.9",
|
||||||
"uglify-js" : "2.4.19",
|
"uglify-js" : "2.4.19",
|
||||||
"formidable" : "1.0.17",
|
"formidable" : "1.0.17",
|
||||||
|
@ -48,7 +49,7 @@
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"wd" : "0.3.11"
|
"wd" : "0.3.11"
|
||||||
},
|
},
|
||||||
"engines" : { "node" : ">=0.6.3",
|
"engines" : { "node" : ">=0.10.0",
|
||||||
"npm" : ">=1.0"
|
"npm" : ">=1.0"
|
||||||
},
|
},
|
||||||
"repository" : { "type" : "git",
|
"repository" : { "type" : "git",
|
||||||
|
|
Loading…
Reference in New Issue