diff options
| -rw-r--r-- | bin/serve.fnl | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/bin/serve.fnl b/bin/serve.fnl index de5b4b3..8235468 100644 --- a/bin/serve.fnl +++ b/bin/serve.fnl @@ -28,25 +28,24 @@ (local pattern (or pattern "%s")) (str:match (.. "^" pattern "*(.-)" pattern "*$"))) -(fn file-exists [path] +(fn file-exists? [path] (local f (io.open path "r")) (and (~= f nil) (io.close f))) (fn router [request] - (local path - (trim - (if (ends-with request.path "/") - (.. request.path "index") - request.path) - "/")) - (local module-path (.. "pages." (string.gsub path "%." "/"))) - ;; FIXME: slow - (if (file-exists (.. "pages/" path ".fnl")) - (do - (local (code headers html) - ((. (require module-path) :render) request)) - (values code headers (.. "<!DOCTYPE html>\n" html))) - (values 404 {:content-type "text/html"} "not found"))) + (let + [path (trim + (if (ends-with request.path "/") + (.. request.path "index") + request.path) + "/") + module-path (.. "pages." (string.gsub path "%." "/")) + module-exists? (file-exists? (.. "pages/" path ".fnl"))] + ;; FIXME: slow + (if module-exists? + (let [(code headers html) ((. (require module-path) :render) request)] + (values code headers (.. "<!DOCTYPE html>\n" html))) + (values 404 {:content-type "text/html"} "not found")))) (luna.router.route "GET /" router) (luna.router.static "GET /static/" "static/") |
