Add built-in exception route

This commit is contained in:
Sdogruyol 2015-11-28 12:39:58 +02:00
parent 58013ba005
commit e1530f8fd5
3 changed files with 10 additions and 2 deletions

View file

@ -107,6 +107,6 @@ describe "Kemal::Handler" do
kemal = Kemal::Handler.new kemal = Kemal::Handler.new
request = HTTP::Request.new("GET", "/?message=world") request = HTTP::Request.new("GET", "/?message=world")
response = kemal.call(request) response = kemal.call(request)
response.body.should eq("hello world") response.status_code.should eq 404
end end
end end

View file

@ -29,5 +29,13 @@ at_exit do
exit exit
} }
# This route serves the built-in images for not_found and exceptions.
get "/__kemal__/:image" do |env|
image = env.params["image"]
file_path = File.expand_path("libs/kemal/images/#{image}", Dir.working_directory)
env.add_header "Content-Type", "application/octet-stream"
File.read(file_path)
end
server.listen server.listen
end end

View file

@ -51,7 +51,7 @@ class Kemal::Handler < HTTP::Handler
</head> </head>
<body> <body>
<h2>Kemal doesn't know this way.</h2> <h2>Kemal doesn't know this way.</h2>
<img src="/images/404.png"> <img src="/__kemal__/404.png">
</body> </body>
</html> </html>
HTML HTML