Add basic set of error pages
Some checks failed
/ Run tests (push) Failing after 1m10s
/ Run system tests (push) Failing after 1m15s
/ Build, push and deploy image (push) Has been skipped

This commit is contained in:
david 2024-11-01 13:16:26 +01:00
parent 823284d6ba
commit d649dc7da3
10 changed files with 115 additions and 41 deletions

29
lib/tasks/app.rake Normal file
View file

@ -0,0 +1,29 @@
desc "Generates error pages"
task generate_error_pages: :environment do
# unless Rails.env.production?
# puts "Skipping generate_error_pages page generation outside production"
# next
# end
Rails.application.config.action_controller.perform_caching = false
pages = {
"error_pages/not_found" => "404.html",
"error_pages/unprocessable_content" => "422.html",
"error_pages/internal_server_error" => "500.html"
}
pages.each do |page, output|
puts "Generating #{output}..."
outpath = Rails.root.join("public", output)
renderer = ApplicationController.renderer.new(http_host: ENV.fetch("APP_HOST") { "jwa11y.top" }, https: true)
html = renderer.render(template: page, layout: "layouts/errors")
if html.present?
File.delete(outpath) if File.exist?(outpath)
File.open(outpath, "w") do |f|
f.write(html)
end
else
puts "Error generating #{output}!"
end
end
end