Skip to content

Commit

Permalink
add some URLs that give us request debug info
Browse files Browse the repository at this point in the history
  • Loading branch information
indirect committed Dec 13, 2024
1 parent 739b3e1 commit 67c7074
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ group :development do
end

group :production do
gem "cloudflare-rails", "~> 6.2"
gem "honeybadger", "~> 5.26"
gem "lograge", "~> 0.14.0"
gem "rack-attack", "~> 6.7"
Expand All @@ -47,6 +46,7 @@ gem "better_html", "~> 2.1"
gem "bootsnap", "~> 1.18", require: false
gem "brotli", "~> 0.6.0"
gem "cloudflare", "~> 4.4"
gem "cloudflare-rails", "~> 6.2"
gem "data_migrate", "~> 11.2"
gem "importmap-rails", "~> 2.0"
gem "jb", "~> 0.8.2"
Expand Down
25 changes: 25 additions & 0 deletions app/controllers/requests_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class RequestsController < ApplicationController
def show
case params[:id]
when "error"
raise "oh no"
when "headers"
render plain: request.headers.to_h.map { |k, v| "#{k}: #{v}" }.sort_by(&:first).join("\n")
when "cloudflare"
render plain: JSON.pretty_generate(
"Rails.configuration.cloudflare": Rails.configuration.cloudflare,
"Importer.cloudflare_ips": CloudflareRails::Importer.cloudflare_ips,
"CloudflareRails::FallbackIps::IPS_V4": CloudflareRails::FallbackIps::IPS_V4,
"CloudflareRails::FallbackIps::IPS_V6": CloudflareRails::FallbackIps::IPS_V6,
"request.headers['REMOTE_ADDR']": request.headers["REMOTE_ADDR"],
"request.forwarded_for": request.forwarded_for,
"request.remote_ip": request.remote_ip,
"request.ip": request.ip,
"request.local?": request.local?,
"request.cloudflare?": request.cloudflare?
)
else
head :not_found
end
end
end
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
end
end
resources :stats, only: [:index]
resources :requests, only: [:show]

get "up" => "rails/health#show"

Expand Down

0 comments on commit 67c7074

Please sign in to comment.