Skip to content

Commit

Permalink
Remove legacy express 3.x middleware getters
Browse files Browse the repository at this point in the history
Remove middleware-getter properties that were simlifying upgrade from
LoopBack 1.x/Express 3.x applications:

  - loopback.compress
  - loopback.timeout
  - loopback.cookieParser
  - loopback.cookieSession
  - loopback.csrf
  - loopback.errorHandler
  - loopback.session
  - loopback.methodOverride
  - loopback.logger
  - loopback.responseTime
  - loopback.favicon
  - loopback.directory
  - loopback.vhost

Also remove `loopback.mime`, which was set to `undefined` anyways.
  • Loading branch information
bajtos committed May 31, 2016
1 parent 70cec07 commit 8d295b7
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 95 deletions.
28 changes: 28 additions & 0 deletions 3.0-RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,31 @@ Developers that are relying on these properties, can redefine them in `user.json
```

Please see [Related code change](https://github.com/strongloop/loopback/pull/2299) here.

## Remove getters for Express 3.x middleware

Express 4.x stopped bundling commonly-used middleware. To simplify migration
of LoopBack 1.x applications (powered by Express 3.x) to LoopBack 2.x (powered
by Express 4.x), we created getter properties to allow developers to keep using
the old convention.

We have removed these getters in LoopBack 3.0, here is the full list of
removed properties together with the middleware module name to use instead:

- `loopback.compress` - use `require('compression')` instead
- `loopback.timeout` - use `require('connect-timeout')` instead
- `loopback.cookieParser` - use `require('cookie-parser')` instead
- `loopback.cookieSession` - use `require('cookie-session')` instead
- `loopback.csrf` - use `require('csurf')` instead
- `loopback.errorHandler` - use `require('errorhandler')` instead
- `loopback.session` - use `require('express-session')` instead
- `loopback.methodOverride` - use `require('method-override')` instead
- `loopback.logger` - use `require('morgan')` instead
- `loopback.responseTime` - use `require('response-time')` instead
- `loopback.favicon` - use `require('serve-favicon')` instead
- `loopback.directory` - use `require('serve-index')` instead
- `loopback.vhost` - use `require('vhost')` instead

We have also removed `loopback.mime`, which was always set to `undefined`.

See [loopback#2349](https://github.com/strongloop/loopback/pull/2394).
57 changes: 0 additions & 57 deletions lib/express-middleware.js

This file was deleted.

21 changes: 1 addition & 20 deletions lib/loopback.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ var juggler = require('loopback-datasource-juggler');
* ```
*
* @property {String} version Version of LoopBack framework. Static read-only property.
* @property {String} mime
* @property {Boolean} isBrowser True if running in a browser environment; false otherwise. Static read-only property.
* @property {Boolean} isServer True if running in a server environment; false otherwise. Static read-only property.
* @property {Registry} registry The global `Registry` object.
Expand All @@ -47,12 +46,6 @@ var loopback = module.exports = createApplication;

loopback.version = require('../package.json').version;

/*!
* Expose mime.
*/

loopback.mime = express.mime;

loopback.registry = new Registry();

Object.defineProperties(loopback, {
Expand Down Expand Up @@ -128,23 +121,11 @@ function mixin(source) {
mixin(require('./runtime'));

/*!
* Expose static express methods like `express.errorHandler`.
* Expose static express methods like `express.Router`.
*/

mixin(express);

/*!
* 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');
mixin(middlewares);
}

/*!
* Expose additional loopback middleware
* for example `loopback.configure` etc.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"body-parser": "^1.12.0",
"canonical-json": "0.0.4",
"continuation-local-storage": "^3.1.3",
"cookie-parser": "^1.3.4",
"debug": "^2.1.2",
"depd": "^1.0.0",
"ejs": "^2.3.1",
Expand All @@ -62,6 +61,7 @@
"devDependencies": {
"browserify": "^10.0.0",
"chai": "^2.1.1",
"cookie-parser": "^1.3.4",
"es5-shim": "^4.1.0",
"eslint-config-loopback": "^1.0.0",
"grunt": "^0.4.5",
Expand Down
8 changes: 7 additions & 1 deletion server/middleware/favicon.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

var favicon = require('serve-favicon');
var path = require('path');

/**
* Serve the LoopBack favicon.
* @header loopback.favicon()
*/
module.exports = require('../../lib/express-middleware').favicon;
module.exports = function(icon, options) {
icon = icon || path.join(__dirname, '../../favicon.ico');
return favicon(icon, options);
};
3 changes: 2 additions & 1 deletion test/access-token.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

var cookieParser = require('cookie-parser');
var loopback = require('../');
var extend = require('util')._extend;
var Token = loopback.AccessToken.extend('MyToken');
Expand Down Expand Up @@ -500,7 +501,7 @@ function createTestApp(testToken, settings, done) {

var app = loopback();

app.use(loopback.cookieParser('secret'));
app.use(cookieParser('secret'));
app.use(loopback.token(tokenSettings));
app.get('/token', function(req, res) {
res.cookie('authorization', testToken.id, { signed: true });
Expand Down
15 changes: 0 additions & 15 deletions test/loopback.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,13 @@ describe('loopback', function() {
'ValidationError',
'application',
'arguments',
'bodyParser',
'caller',
'compress',
'configureModel',
'context',
'cookieParser',
'cookieSession',
'createContext',
'createDataSource',
'createModel',
'csrf',
'defaultDataSources',
'directory',
'errorHandler',
'favicon',
'faviconFile',
Expand All @@ -80,12 +74,8 @@ describe('loopback', function() {
'getModelByType',
'isBrowser',
'isServer',
'json',
'length',
'logger',
'memory',
'methodOverride',
'mime',
'modelBuilder',
'name',
'prototype',
Expand All @@ -94,19 +84,14 @@ describe('loopback', function() {
'remoteMethod',
'request',
'response',
'responseTime',
'rest',
'runInContext',
'session',
'static',
'status',
'template',
'timeout',
'token',
'urlNotFound',
'urlencoded',
'version',
'vhost',
];

var actual = Object.getOwnPropertyNames(loopback);
Expand Down

0 comments on commit 8d295b7

Please sign in to comment.