Node.js Sails.js:删除特定路由的bodyparser中间件

Node.js Sails.js:删除特定路由的bodyparser中间件,node.js,sails.js,body-parser,Node.js,Sails.js,Body Parser,有没有办法删除特定路由的中间件 目前所有的中间件都列在http.js文件中 [ 'startRequestTimer', 'cookieParser', 'session', 'bodyParser', 'passportInit', 'passportSession', 'myRequestLogger', 'handleBodyParserError', 'compress',

有没有办法删除特定路由的中间件

目前所有的中间件都列在
http.js
文件中

[
      'startRequestTimer',
      'cookieParser',
      'session',
      'bodyParser',
      'passportInit',
      'passportSession',
      'myRequestLogger',
      'handleBodyParserError',
      'compress',
      'methodOverride',
      'poweredBy',
      'router',
      'www',
      'favicon',
      '404',
      '500'
  ]
我想删除特定路由的
bodyParser
中间件


有可能使用sails.js吗?

没有声明式的机制,但是可以根据每个路由禁用中间件。您可以通过覆盖中间件并在自定义代码中检查路由URL来实现这一点,类似于的解决方案。例如:

// In config/http.js `middleware` property

bodyParser: (function() {
  // Initialize a skipper instance with the default options.
  var skipper = require('skipper')();
  // Create and return the middleware function.
  return function(req, res, next) {
    // If we see the route we want skipped, just continue.
    if (req.url === '/dont-parse-me') {
      return next();
    }
    // Otherwise use Skipper to parse the body.
    return skipper(req, res, next);
  };
})()

这是基本的想法。当然可以做得更优雅一点;例如,如果要跳过多个路由,可以将列表保存在单独的文件中,并根据该列表检查当前URL。

因此,我需要调用bodyParser中间件,以便默认情况下arrayIt已经在其中。如果您有一个自定义的
顺序
数组,那么是的,您需要确保
bodyParser
在其中,以便此解决方案能够工作。因此,这里我覆盖默认的bodyParser中间件,对吗?没错,尽管对于大多数路由,上面的代码仍将使用Skipper,这是默认情况下通常发生的情况。