-
Notifications
You must be signed in to change notification settings - Fork 18
/
start-server.lua
79 lines (64 loc) · 1.92 KB
/
start-server.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
local xavante = require "xavante"
local filehandler = require "xavante.filehandler"
local cgiluahandler = require "xavante.cgiluahandler"
local redirect = require "xavante.redirecthandler"
local conf = (require "conf.conf").sailor
-- Define here where Xavante HTTP documents scripts are located
local webDir = "."
local uri_map
if conf.friendly_urls then
uri_map = { -- URI remapping
match = "^[^%./]*/?([^%.]*)$",
with = redirect,
params = {
"/",
function(req,res,cap)
local vars = {}
for var in string.gmatch(cap[1], '([^/]+)') do
table.insert(vars,var)
end
if #vars > 0 then
local mod = (#vars % 2) - 1
local get = ""
if #vars > 1 - mod then
for i = 2 - mod, #vars, 2 do
get = get.."&"..vars[i].."="..vars[i+1]
end
end
if mod == -1 then
get = vars[2]..get
end
req.cmd_url = "/index.lua?"..conf.route_parameter.."="..vars[1].."/"..get
else
req.cmd_url = "/index.lua"
end
return "reparse"
end
}
}
else
uri_map = {
match = "^[^%./]*/$",
with = redirect,
params = {"index.lua"}
}
end
local simplerules = {
uri_map,
{ -- cgiluahandler example
match = {"%.lp$", "%.lp/.*$", "%.lua$", "%.lua/.*$" },
with = cgiluahandler.makeHandler (webDir,{ reload = true })
},
{ -- filehandler example
match = ".",
with = filehandler,
params = {baseDir = webDir}
},
}
xavante.HTTP{
server = {host = "*", port = 8080},
defaultHost = {
rules = simplerules
}
}
xavante.start()