You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.7 KiB
Lua
65 lines
1.7 KiB
Lua
local cjson = require "cjson"
|
|
local redis = require "redis"
|
|
local util = require "utils"
|
|
local waf = require "waf"
|
|
local toml = require "toml"
|
|
local http = require "http"
|
|
local mysql = require "mysql"
|
|
|
|
require "functions"
|
|
|
|
math.randomseed(tostring(ngx.time()):reverse():sub(1, 6));
|
|
|
|
local workerId = ngx.worker.id()
|
|
|
|
local config = nil
|
|
|
|
DEBUG=nil
|
|
|
|
local function file_exists(name)
|
|
local f=io.open(name,"r")
|
|
if f~=nil then io.close(f) return true else return false end
|
|
end
|
|
|
|
local function read_file(path)
|
|
local file = io.open(path, "r") -- r read mode and b binary mode
|
|
if not file then return nil end
|
|
local content = file:read "*a" -- *a or *all reads the whole file
|
|
file:close()
|
|
return content
|
|
end
|
|
|
|
if file_exists("../config/dev.toml") then
|
|
DEBUG = true
|
|
local content = read_file("../config/dev.toml")
|
|
config=toml.parse(content)
|
|
|
|
else
|
|
local content = read_file("../config/prod.toml")
|
|
config=toml.parse(content)
|
|
end
|
|
ngx.log(ngx.INFO,"config =======================>",cjson.encode(config))
|
|
|
|
APPNAME = config.global.appname
|
|
ngx.log(ngx.DEBUG, "APPNAME=", APPNAME)
|
|
|
|
APPVERSION = config.global.appversion
|
|
ngx.log(ngx.DEBUG, "APPVERSION=", APPVERSION)
|
|
|
|
|
|
REDIS_CONFIG = config.redis
|
|
ngx.log(ngx.DEBUG, "REDIS_CONFIG=", cjson.encode(REDIS_CONFIG))
|
|
|
|
QUEUE_CONFIG = config.queue
|
|
ngx.log(ngx.DEBUG, "QUEUE_CONFIG=", cjson.encode(QUEUE_CONFIG))
|
|
|
|
MYSQL_CONFIG = config.mysql
|
|
ngx.log(ngx.DEBUG, "MYSQL_CONFIG=", cjson.encode(MYSQL_CONFIG))
|
|
|
|
MONGO_CONFIG = config.mongo
|
|
ngx.log(ngx.DEBUG, "MONGO_CONFIG=", cjson.encode(MONGO_CONFIG))
|
|
|
|
|
|
ngx.log(ngx.DEBUG,"Init Waf")
|
|
waf.init()
|