diff --git a/.gitignore b/.gitignore index 7be2743..db6628d 100644 --- a/.gitignore +++ b/.gitignore @@ -24,4 +24,5 @@ go.work # Test directories and files test.lua -test_fs_dir \ No newline at end of file +test_fs_dir +public \ No newline at end of file diff --git a/modules/http/http.lua b/modules/http/http.lua index 101f963..214a2c9 100644 --- a/modules/http/http.lua +++ b/modules/http/http.lua @@ -72,24 +72,22 @@ local function match_route(method, path) return nil, {} end --- Global handler function called by Go workers function _http_handle_request(req_table, res_table) local req = Request.new(req_table) local res = Response.new(res_table) - -- Find matching route - local route, params = match_route(req.method, req.path) - req.params = params - - if not route then - res:status(404):send("Not Found") - return - end - - -- Execute middleware chain + -- Execute middleware chain first local function run_middleware(index) if index > #_G._http_middleware then - -- All middleware executed, run route handler + local route, params = match_route(req.method, req.path) + req.params = params + + if not route then + res:status(404):send("Not Found") + return + end + + -- Run route handler route.handler(req, res) return end @@ -557,6 +555,7 @@ function http.static(root_path) [".jpeg"] = "image/jpeg", [".gif"] = "image/gif", [".svg"] = "image/svg+xml", + [".webp"] = "image/webp", [".txt"] = "text/plain", }