我不得不修改Vishnu中的代码,这是使其适用于发布请求的公认答案,因此如果您有发布请求,则需要从响应正文中取出参数:
class TrelloWebhooks def initialize(app) @app = app end def call(env) request = Rack::Request.new(env) body = JSON.parse(request.body.string) trello_action = body["action"] request.update_param('trello_action', trello_action) status, headers, response = @app.call(env) [status, headers, response] end end Rails.application.config.middleware.use 'TrelloWebhooks'
您可以在初始化程序中编写中间件并更新来自trello webhooks的参数。如下 -
class TrelloWebhooks def initialize(app) @app = app end def call(env) request = Rack::Request.new(env) trello_action = request.params['action'] request.update_param('trello_action', trello_action) status, headers, response = @app.call(env) [status, headers, response] end end Rails.application.config.middleware.use 'TrelloWebhooks'