From 88a4bb462e6b8765ec04ccb37d69a810afed7fe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Tue, 3 Jun 2014 10:15:15 +0200 Subject: [PATCH] Exclude express-middleware from browser bundle Fix lib/loopback to include express-middleware only on the server. Bump up strong-remoting dependency to use the version working in browsers. --- lib/express-middleware.js | 6 +----- lib/loopback.js | 26 ++++++++++++++++++-------- package.json | 2 +- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/lib/express-middleware.js b/lib/express-middleware.js index 4da2e598..cc67278c 100644 --- a/lib/express-middleware.js +++ b/lib/express-middleware.js @@ -1,7 +1,7 @@ var express = require('express'); var path = require('path'); -var middlewares = express.middlewares = {}; +var middlewares = exports; function safeRequire(m) { try { @@ -50,7 +50,3 @@ middlewares.favicon = function (icon, options) { icon = icon || path.join(__dirname, '../favicon.ico'); return favicon(icon, options); }; - -module.exports = express; - - diff --git a/lib/loopback.js b/lib/loopback.js index 47a575e9..4f9859ca 100644 --- a/lib/loopback.js +++ b/lib/loopback.js @@ -2,7 +2,7 @@ * Module dependencies. */ -var express = require('./express-middleware') +var express = require('express') , fs = require('fs') , ejs = require('ejs') , path = require('path') @@ -89,8 +89,7 @@ function createApplication() { } /*! - * Expose express.middleware as loopback.* - * for example `loopback.errorHandler` etc. + * Expose static express methods like `express.errorHandler`. */ for (var key in express) { @@ -100,11 +99,22 @@ for (var key in express) { , Object.getOwnPropertyDescriptor(express, key)); } -for (var key in express.middlewares) { - Object.defineProperty( - loopback - , key - , Object.getOwnPropertyDescriptor(express.middlewares, key)); +/*! + * Expose additional middleware like session as loopback.* + * This will keep the loopback API compatible with express 3.x + * + * ***only in node*** + */ + +if (loopback.isServer) { + var middlewares = require('./express-middleware'); + + for (var key in middlewares) { + Object.defineProperty( + loopback + , key + , Object.getOwnPropertyDescriptor(middlewares, key)); + } } /*! diff --git a/package.json b/package.json index 24be7f55..a1601bf0 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "debug": "~0.8.1", "express": "4.x", "body-parser": "~1.2.2", - "strong-remoting": "2.0.0-beta2", + "strong-remoting": "2.0.0-beta3", "inflection": "~1.3.5", "passport": "~0.2.0", "passport-local": "~1.0.0",