basic API to be used in swarm mode

This commit is contained in:
bunkerity
2021-03-12 10:42:31 +01:00
parent 781e4c8cbb
commit 7509ec2f2c
5 changed files with 64 additions and 0 deletions

28
lua/api.lua Normal file
View File

@@ -0,0 +1,28 @@
local M = {}
local api_uri = "%API_URI%"
local api_list = {}
api_list["^/reload$"] = function ()
return os.execute("/usr/sbin/nginx -s reload") == 0
end
function M.is_api_call ()
if ngx.var.request_uri:sub(1, #api_uri) .. "/" == api_uri .. "/" then
for uri, code in pairs(api_list) do
if string.match(ngx.var.request_uri:sub(#api_uri + 1), uri) then
return true
end
end
end
return false
end
function M.do_api_call ()
for uri, code in pairs(api_list) do
if string.match(ngx.var.request_uri:sub(#api_uri + 1), uri) then
return code()
end
end
end
return M