webmcp
view framework/env/request/default_router.lua @ 496:3b4dbabca31f
Bugfix in request.handler(...) for allowing actions to directly return content
author | jbe |
---|---|
date | Sun Jul 02 04:22:20 2017 +0200 (2017-07-02) |
parents | 32b79658e5ae |
children |
line source
1 --[[--
2 route =
3 request.default_router(
4 path -- URL path without leading slash
5 )
7 Default conversion from a path to a route. Called by request.router().
9 --]]--
11 function request.default_router(path)
12 if not path then
13 return nil
14 end
15 if path == "" then
16 return {module = "index", view = "index"}
17 end
18 local static = string.match(path, "^static/([-./0-9A-Z_a-z]*)$")
19 if static then
20 -- Note: sanitizer is in request.handler(...)
21 return {static = static}
22 end
23 local module, action, view, id, suffix
24 module = string.match(path, "^([^/]+)/$")
25 if module then
26 return {module = module, view = "index"}
27 end
28 module, action = string.match(path, "^([^/]+)/([^/.]+)$")
29 if module then
30 return {module = module, action = action}
31 end
32 module, view, suffix = string.match(path, "^([^/]+)/([^/.]+)%.([^/]+)$")
33 if module then
34 return {module = module, view = view, suffix = suffix}
35 end
36 module, view, id, suffix = string.match(path, "^([^/]+)/([^/]+)/([^/.]+)%.([^/]+)$")
37 if module then
38 return {module = module, view = view, id = id, suffix = suffix}
39 end
40 return nil
41 end
43 --//--