diff --git a/lib/express-middleware.js b/lib/express-middleware.js index cc7596ff..98fae040 100644 --- a/lib/express-middleware.js +++ b/lib/express-middleware.js @@ -4,6 +4,7 @@ // License text available at https://opensource.org/licenses/MIT var path = require('path'); +var deprecated = require('depd')('loopback'); var middlewares = exports; @@ -29,12 +30,10 @@ var middlewareModules = { 'cookieParser': 'cookie-parser', 'cookieSession': 'cookie-session', 'csrf': 'csurf', - 'errorHandler': 'errorhandler', 'session': 'express-session', 'methodOverride': 'method-override', 'logger': 'morgan', 'responseTime': 'response-time', - 'favicon': 'serve-favicon', 'directory': 'serve-index', // 'static': 'serve-static', 'vhost': 'vhost' @@ -44,14 +43,20 @@ middlewares.bodyParser = safeRequire('body-parser'); middlewares.json = middlewares.bodyParser && middlewares.bodyParser.json; middlewares.urlencoded = middlewares.bodyParser && middlewares.bodyParser.urlencoded; +['bodyParser', 'json', 'urlencoded'].forEach(function(name) { + if (!middlewares[name]) return; + middlewares[name] = deprecated.function( + middlewares[name], + deprecationMessage(name, 'body-parser')); +}); + for (var m in middlewareModules) { var moduleName = middlewareModules[m]; middlewares[m] = safeRequire(moduleName) || createMiddlewareNotInstalled(m, moduleName); + deprecated.property(middlewares, m, deprecationMessage(m, moduleName)); } -// serve-favicon requires a path -var favicon = middlewares.favicon; -middlewares.favicon = function(icon, options) { - icon = icon || path.join(__dirname, '../favicon.ico'); - return favicon(icon, options); -}; +function deprecationMessage(accessor, moduleName) { + return 'loopback.' + accessor + ' is deprecated. ' + + 'Use `require(\'' + moduleName + '\');` instead.'; +} diff --git a/server/middleware/favicon.js b/server/middleware/favicon.js index b5cf10ce..48ffac4f 100644 --- a/server/middleware/favicon.js +++ b/server/middleware/favicon.js @@ -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); +}; diff --git a/test/access-token.test.js b/test/access-token.test.js index 573cae5a..53b0996e 100644 --- a/test/access-token.test.js +++ b/test/access-token.test.js @@ -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'); @@ -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});