Created
October 2, 2023 16:41
-
-
Save DevGW/87d16a9aff5a63f7725e7cec2e7b42c1 to your computer and use it in GitHub Desktop.
Add middleware request logging for token testing to rails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#config/request_logger.rb | |
### NOTE: add the following two lines (uncommented) to your config/application.rb to load the middleware | |
# require_relative 'request_logger' | |
# config.middleware.use RequestLogger | |
class RequestLogger | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
request = Rack::Request.new(env) | |
Rails.logger.info("Headers: #{request.env.select { |k, _| k.start_with?('HTTP_') }}") | |
@app.call(env) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment