-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroute.lua
34 lines (27 loc) · 798 Bytes
/
route.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
local routes = {}
routes['^/(.*).(jpg|gif|png|css|js|ico|swf|flv|mp3|mp4|woff|eot|ttf|otf|svg)$'] = function()
header('Cache-Control: max-age=864000')
sendfile(headers.uri)
end
routes['^/user/:user_id'] = function(r)
print('User ID: ', r.user_id)
end
routes['^/user/:user_id/:post(.+)'] = function(r)
print('User ID: ', r.user_id)
print(' Post: ', r.post)
end
routes['^/(.*)'] = function(r)
dofile('/scripts/index.lua')
end
routes['^/scripts/:file(.*)'] = function(r)
dofile('/scripts/'..r.file..'.lua')
end
--[[
others you want :)
]]
-- if the 3rd argument is a path, then router will try to get local lua script file first
local ok, err, arg = router(headers.uri, routes, '/')
if not ok then
header('HTTP/1.1 404 Not Found')
echo('File Not Found!')
end