Sha256: 888c732f43e1a511bda2124cdc5b3aad895ac4a020f416b51974262f507ce25b

Contents?: true

Size: 1.14 KB

Versions: 17

Compression:

Stored size: 1.14 KB

Contents

/*!
 * Connect - methodOverride
 * Copyright(c) 2010 Sencha Inc.
 * Copyright(c) 2011 TJ Holowaychuk
 * MIT Licensed
 */

/**
 * Module dependencies.
 */

var deprecate = require('depd')('connect');
var methodOverride = require('method-override');

/**
 * Method Override:
 *
 * See [method-override](https://github.com/expressjs/method-override)
 *
 * @param {String} key
 * @return {Function}
 * @api public
 */

module.exports = function(key){
  // this is a shim to keep the interface working with method-override@2
  var opts = { methods: null };
  var prop = key || '_method';
  var _headerOverride = methodOverride('X-HTTP-Method-Override', opts);
  var _bodyOverride = methodOverride(function(req){
    if (req.body && typeof req.body === 'object' && prop in req.body) {
      var method = req.body[prop];
      delete req.body[prop];
      return method;
    }
  }, opts);

  return function(req, res, next){
    _bodyOverride(req, res, function(err){
      if (err) return next(err);
      _headerOverride(req, res, next);
    });
  };
};

module.exports = deprecate.function(module.exports,
  'methodOverride: use method-override npm module instead');

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
hooch-0.4.2 jasmine/node_modules/karma/node_modules/connect/lib/middleware/methodOverride.js
hooch-0.4.1 jasmine/node_modules/karma/node_modules/connect/lib/middleware/methodOverride.js
hooch-0.4.0 jasmine/node_modules/karma/node_modules/connect/lib/middleware/methodOverride.js
hooch-0.3.0 jasmine/node_modules/karma/node_modules/connect/lib/middleware/methodOverride.js
hooch-0.2.1 jasmine/node_modules/karma/node_modules/connect/lib/middleware/methodOverride.js
hooch-0.2.0 jasmine/node_modules/karma/node_modules/connect/lib/middleware/methodOverride.js
hooch-0.1.0 jasmine/node_modules/karma/node_modules/connect/lib/middleware/methodOverride.js
hooch-0.0.8 jasmine/node_modules/karma/node_modules/connect/lib/middleware/methodOverride.js
hooch-0.0.7 jasmine/node_modules/karma/node_modules/connect/lib/middleware/methodOverride.js
hooch-0.0.6 jasmine/node_modules/karma/node_modules/connect/lib/middleware/methodOverride.js
entangled-0.0.16 spec/dummy/public/node_modules/karma/node_modules/connect/lib/middleware/methodOverride.js
entangled-0.0.15 spec/dummy/public/node_modules/karma/node_modules/connect/lib/middleware/methodOverride.js
entangled-0.0.14 spec/dummy/public/node_modules/karma/node_modules/connect/lib/middleware/methodOverride.js
entangled-0.0.13 spec/dummy/public/node_modules/karma/node_modules/connect/lib/middleware/methodOverride.js
entangled-0.0.12 spec/dummy/public/node_modules/karma/node_modules/connect/lib/middleware/methodOverride.js
entangled-0.0.11 spec/dummy/public/node_modules/karma/node_modules/connect/lib/middleware/methodOverride.js
entangled-0.0.10 spec/dummy/public/node_modules/karma/node_modules/connect/lib/middleware/methodOverride.js