|
|
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"
|
|
|
|
|
|
local body = cjson.encode(config)
|
|
|
ngx.say(body)
|
|
|
ngx.exit(ngx.HTTP_OK)
|
|
|
end |
...
|
...
|
|