33 lines
919 B
Plaintext
33 lines
919 B
Plaintext
# todo : if api_uri == "random"
|
|
location ~ ^{{ API_URI }}/ping {
|
|
return 444;
|
|
}
|
|
|
|
location ~ {{ API_URI }} {
|
|
|
|
rewrite_by_lua_block {
|
|
|
|
local api = require "api"
|
|
local api_whitelist_ip = {% raw %}{{% endraw %}{% set elements = API_WHITELIST_IP.split(" ") %}{% for i in range(0, elements|length) %}"{{ elements[i] }}"{% if i < elements|length-1 %},{% endif %}{% endfor %}{% raw %}}{% endraw %}
|
|
local api_uri = "{{ API_URI }}"
|
|
local logger = require "logger"
|
|
|
|
if api.is_api_call(api_uri, api_whitelist_ip) then
|
|
ngx.header.content_type = 'text/plain'
|
|
if api.do_api_call(api_uri) then
|
|
logger.log(ngx.NOTICE, "API", "API call " .. ngx.var.request_uri .. " successfull from " .. ngx.var.remote_addr)
|
|
ngx.say("ok")
|
|
else
|
|
logger.log(ngx.WARN, "API", "API call " .. ngx.var.request_uri .. " failed from " .. ngx.var.remote_addr)
|
|
ngx.say("ko")
|
|
end
|
|
|
|
ngx.exit(ngx.HTTP_OK)
|
|
|
|
end
|
|
|
|
ngx.exit(ngx.OK)
|
|
}
|
|
|
|
}
|