httpd: wip show_page
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
diff --git a/lib/kc3/0.1/httpd.kc3 b/lib/kc3/0.1/httpd.kc3
index f07b2c6..7c214d1 100644
--- a/lib/kc3/0.1/httpd.kc3
+++ b/lib/kc3/0.1/httpd.kc3
@@ -98,13 +98,36 @@ defmodule HTTPd do
%HTTP.Response{body: body}
}
+ def show_page = fn (request) {
+ path = root_dir + request.url
+ if File.exists?(path) do
+ body = File.read(path)
+ body = "<html>
+ <head>
+ <title>#{request.url}</title>
+ </head>
+ <body>
+ #{body}
+ </body>
+</html>
+"
+ %HTTP.Response{body: body}
+ else
+ error_404_page(request)
+ end
+ }
+
def route_request = fn (request) {
path = root_dir + request.url
if File.exists?(path) do
if File.is_directory?(path) do
directory_page
else
- debug_page
+ if Str.ends_with?(path, ".html") do
+ show_page
+ else
+ debug_page
+ end
end
else
error_404_page