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

update express to version 4 #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 5 additions & 5 deletions lib/subservers.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ function getAdditionalSubservers(subserverHandler) {

function runFuncAndRecordNewExpressRoutes(app, func, context) {
var method, oldRoutes = {};
for (method in app.routes) { oldRoutes[method] = [].concat(app.routes[method]); }
for (method in ['post', 'get', 'delete', 'put'].map(rt => [rt, app._router.stack.map(r => r.route).filter(r => r && r.methods[rt])]).reduce((acc, elem) => {acc[elem[0]] = elem[1]; return acc}, {})) { oldRoutes[method] = [].concat(['post', 'get', 'delete', 'put'].map(rt => [rt, app._router.stack.map(r => r.route).filter(r => r && r.methods[rt])]).reduce((acc, elem) => {acc[elem[0]] = elem[1]; return acc}, {})[method]); }
// 2) run the function
func.call(context);
// 3) find new routes and remember them has belonging to this subserver
var newRoutes = [];
for (method in app.routes) {
app.routes[method].forEach(function(route) {
for (method in ['post', 'get', 'delete', 'put'].map(rt => [rt, app._router.stack.map(r => r.route).filter(r => r && r.methods[rt])]).reduce((acc, elem) => {acc[elem[0]] = elem[1]; return acc}, {})) {
['post', 'get', 'delete', 'put'].map(rt => [rt, app._router.stack.map(r => r.route).filter(r => r && r.methods[rt])]).reduce((acc, elem) => {acc[elem[0]] = elem[1]; return acc}, {})[method].forEach(function(route) {
if (oldRoutes[method].indexOf(route) === -1) newRoutes.push(route);
});
}
Expand All @@ -61,7 +61,7 @@ function runFuncAndRecordNewExpressRoutes(app, func, context) {

function removeRouteFromExpressApp(app, route) {
if (!app) return false;
var routes = app.routes[route.method],
var routes = ['post', 'get', 'delete', 'put'].map(rt => [rt, app._router.stack.map(r => r.route).filter(r => r && r.methods[rt])]).reduce((acc, elem) => {acc[elem[0]] = elem[1]; return acc}, {})[route.method],
idx = routes.indexOf(route);
if (idx === -1) return false;
routes.splice(idx, 1);
Expand Down Expand Up @@ -102,7 +102,7 @@ Subserver.prototype.start = function(app) {
self.myRegisteredRoutes = newRoutes;
// push subserver routes at the start of the route list so they can match
newRoutes.reverse().forEach(function(route) {
var routes = app.routes[route.method];
var routes = ['post', 'get', 'delete', 'put'].map(rt => [rt, app._router.stack.map(r => r.route).filter(r => r && r.methods[rt])]).reduce((acc, elem) => {acc[elem[0]] = elem[1]; return acc}, {})[route.method];
routes.splice(routes.indexOf(route), 1);
routes.unshift(route);
});
Expand Down
42 changes: 22 additions & 20 deletions life_star.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const cookieSession = require('cookie-session');
/*global require, module*/
var lang = require('lively.lang'),
express = require('express'),
Expand Down Expand Up @@ -96,23 +99,22 @@ var serverSetup = module.exports = function(config, thenDo) {

function createServer(next) {
if (config.enableSSL) {
var https = require('https'),
options = {
// Specify the key and certificate file
key: fs.readFileSync(config.sslServerKey),
cert: fs.readFileSync(config.sslServerCert),
// Specify the Certificate Authority certificate
ca: fs.readFileSync(config.sslCACert),

// This is where the magic happens in Node. All previous steps simply
// setup SSL (except the CA). By requesting the client provide a
// certificate, we are essentially authenticating the user.
requestCert: config.enableSSLClientAuth,

// If specified as "true", no unauthenticated traffic will make it to
// the route specified.
rejectUnauthorized: config.enableSSLClientAuth
};
var options = {
// Specify the key and certificate file
key: fs.readFileSync(config.sslServerKey),
cert: fs.readFileSync(config.sslServerCert),
// Specify the Certificate Authority certificate
ca: fs.readFileSync(config.sslCACert),

// This is where the magic happens in Node. All previous steps simply
// setup SSL (except the CA). By requesting the client provide a
// certificate, we are essentially authenticating the user.
requestCert: config.enableSSLClientAuth,

// If specified as "true", no unauthenticated traffic will make it to
// the route specified.
rejectUnauthorized: config.enableSSLClientAuth
};
server = require('https').createServer(options, app);
} else {
server = require('http').createServer(app);
Expand Down Expand Up @@ -209,17 +211,17 @@ var serverSetup = module.exports = function(config, thenDo) {
}

function setupBodyParser(next) {
app.use(express.bodyParser({limit: '150mb'}));
app.use(bodyParser({limit: '150mb'}));
next();
}

function setupCookies(next) {
app.use(express.cookieParser());
app.use(cookieParser());

// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// store auth information into a cookie
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
app.use(express.cookieSession({
app.use(cookieSession({
key: 'livelykernel-sign-on',
secret: 'foo',
proxy: config.behindProxy,
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
"description": "Another web server for Lively",
"dependencies": {
"async": "~0.9",
"express": "~3",
"express": "^4.0.0",
"lively-davfs": "^0.4.4",
"log4js": "0.4.1",
"morgan": ">=1.2.0",
"request": "~2.2",
"lively.lang": "^0.7"
"lively.lang": "^0.7",
"body-parser": "^1.19.0",
"cookie-parser": "^1.4.4",
"cookie-session": "^1.4.0"
},
"devDependencies": {
"nodeunit": ""
Expand Down