sec.lua
1.01 KB
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
local modname= ...
local M={}
_G[modname]=M
package.loaded[modname]=M
local cjson=require "cjson"
local config = {}
-- load config files from local
local function load_config()
local myTable = {}
local file = io.open( "/usr/local/openresty/nginx/conf/sec.config.json", "r" )
if file then
--print("trying to read ", filename)
-- read all contents of file into a string
local contents = file:read( "*a" )
myTable = cjson.decode(contents);
io.close( file )
--print("Loaded file")
return myTable
else
ngx.log(ngx.ERR, "file is not found. ")
return nil
end
end
--- called by init_worker_by_lua_file
function M:init()
config = load_config()
end
-- get all config --------
function M:get_config()
ngx.header["Content-type"]="application/json;charset=utf-8"
if next(config) == nil then
ngx.log(ngx.ERR, "config not found. ")
ngx.exit(ngx.HTTP_NOT_FOUND)
else
local body = cjson.encode(config)
ngx.say(body)
ngx.exit(ngx.HTTP_OK)
end
end