Commit 263c9d5028b18f61777dfa12f53f881ed9f39162

Baptiste 2024-08-07T13:41:19

httpd: wip show_page

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