adjust static file handling

This commit is contained in:
Sky Johnson 2025-07-17 19:07:25 -05:00
parent 1753007090
commit e95f0f3370
2 changed files with 13 additions and 13 deletions

1
.gitignore vendored
View File

@ -25,3 +25,4 @@ go.work
# Test directories and files # Test directories and files
test.lua test.lua
test_fs_dir test_fs_dir
public

View File

@ -72,12 +72,13 @@ local function match_route(method, path)
return nil, {} return nil, {}
end end
-- Global handler function called by Go workers
function _http_handle_request(req_table, res_table) function _http_handle_request(req_table, res_table)
local req = Request.new(req_table) local req = Request.new(req_table)
local res = Response.new(res_table) local res = Response.new(res_table)
-- Find matching route -- Execute middleware chain first
local function run_middleware(index)
if index > #_G._http_middleware then
local route, params = match_route(req.method, req.path) local route, params = match_route(req.method, req.path)
req.params = params req.params = params
@ -86,10 +87,7 @@ function _http_handle_request(req_table, res_table)
return return
end end
-- Execute middleware chain -- Run route handler
local function run_middleware(index)
if index > #_G._http_middleware then
-- All middleware executed, run route handler
route.handler(req, res) route.handler(req, res)
return return
end end
@ -557,6 +555,7 @@ function http.static(root_path)
[".jpeg"] = "image/jpeg", [".jpeg"] = "image/jpeg",
[".gif"] = "image/gif", [".gif"] = "image/gif",
[".svg"] = "image/svg+xml", [".svg"] = "image/svg+xml",
[".webp"] = "image/webp",
[".txt"] = "text/plain", [".txt"] = "text/plain",
} }