webmcp

view framework/env/request/default_router.lua @ 250:db79324a13fe

Work on static file delivery
author jbe
date Sun Mar 01 21:38:07 2015 +0100 (2015-03-01)
parents 4ab91adeab6f
children 169dfbd0246a
line source
1 --[[--
2 route =
3 request.default_router(
4 path -- URL path, including a 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 if
21 string.match(static, "^/") or
22 string.match(static, "//") or
23 string.match(static, "/$") or
24 string.match(static, "^%.%.?$") or
25 string.match(static, "/%.%.?$") or
26 string.match(static, "^%.%.?/") or
27 string.match(static, "/%.%.?/") -- TODO: improve
28 then
29 return nil
30 else
31 return {static = static}
32 end
33 end
34 local module, action, view, id, suffix
35 module = string.match(path, "^([^/]+)/$")
36 if module then
37 return {module = module, view = "index"}
38 end
39 module, action = string.match(path, "^([^/]+)/([^/.]+)$")
40 if module then
41 return {module = module, action = action}
42 end
43 module, view, suffix = string.match(path, "^([^/]+)/([^/.]+)%.([^/]+)$")
44 if module then
45 return {module = module, view = view, suffix = suffix}
46 end
47 module, view, id, suffix = string.match(path, "^([^/]+)/([^/]+)/([^/.]+)%.([^/]+)$")
48 if module then
49 return {module = module, view = view, id = id, suffix = suffix}
50 end
51 return nil
52 end
54 --//--

Impressum / About Us