# HG changeset patch # User jbe # Date 1425242287 -3600 # Node ID db79324a13fec19dd1ff8db5fa6c19aa3fd5637c # Parent b4b6e1fc74e84e6b9c65f89cdfd4174d92ca9771 Work on static file delivery diff -r b4b6e1fc74e8 -r db79324a13fe framework/env/request/default_router.lua --- a/framework/env/request/default_router.lua Sun Mar 01 21:20:29 2015 +0100 +++ b/framework/env/request/default_router.lua Sun Mar 01 21:38:07 2015 +0100 @@ -12,10 +12,26 @@ if not path then return nil end - local module, action, view, id, suffix if path == "" then return {module = "index", view = "index"} end + local static = string.match(path, "^static/([-./0-9A-Z_a-z]+)$") + if static then + if + string.match(static, "^/") or + string.match(static, "//") or + string.match(static, "/$") or + string.match(static, "^%.%.?$") or + string.match(static, "/%.%.?$") or + string.match(static, "^%.%.?/") or + string.match(static, "/%.%.?/") -- TODO: improve + then + return nil + else + return {static = static} + end + end + local module, action, view, id, suffix module = string.match(path, "^([^/]+)/$") if module then return {module = module, view = "index"} diff -r b4b6e1fc74e8 -r db79324a13fe framework/env/request/process.lua --- a/framework/env/request/process.lua Sun Mar 01 21:20:29 2015 +0100 +++ b/framework/env/request/process.lua Sun Mar 01 21:38:07 2015 +0100 @@ -15,6 +15,14 @@ local success, error_info = xpcall( function() + if request._route.static then + local f = assert(file.open(request._route.static, "r")) + local d = f:read("*a") + f:close() + slot.put_into("data", d) + slot.set_layout(nil, "application/octet-stream") -- TODO + end + -- restore slots if coming from http redirect local tempstore_value = request._http_request.get_params["_tempstore"] if tempstore_value then