-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinit.lua
executable file
·68 lines (51 loc) · 1.71 KB
/
init.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
#!/usr/bin/env jazz
-- Jazz Flute
_G.cwd = fs.canonicalize(env.current_dir()) .. "/"
require "config"
_G.log = require "third-party.log"
log.level = settings.log_level or "info"
-- this config must be before requires
package.path = package.path ..";" .. cwd .. "?.lua;"
--
-- TODO: refactor out into a library (and make it prettier)
local _req = require
function require (module_name)
local is_new = package.loaded[module_name] == nil
local mod = _req(module_name)
if is_new and type(mod) == "function" then
log.debug("Patched module function " .. module_name)
local _mod = mod
function mod (...)
local args_str = table.concat({...}, ", ")
log.trace("[function] " .. module_name .. "(" .. args_str .. ")")
local function fn (...) return {...} end
local result = fn(_mod(...))
local rets_str = table.concat({rets_tbl}, ", ")
log.trace("[function] " .. module_name .. " returned " .. rets_str)
return table.unpack(result)
end
package.loaded[module_name] = mod
end
return mod
end
require "mod"
require "base"
local address = torchbear.settings and torchbear.settings.address or "localhost"
local port = torchbear.settings and torchbear.settings.port or "3000"
log.info("[starting] web server on " .. address .. ":" .. port)
-- Handler function
return function (request)
_G.lighttouch_response = nil
local event_parameters = { }
event_parameters["request"] = request
events["incoming_request_received"]:trigger(event_parameters)
for k, v in pairs(rules) do
v.rule(request)
end
if lighttouch_response then
events["outgoing_response_about_to_be_sent"]:trigger({
response = lighttouch_response
})
end
return lighttouch_response
end