Merge pull request #5175 from whalecold/refactor
Migrate the backends handle logic to function
This commit is contained in:
commit
e152ee3688
1 changed files with 32 additions and 27 deletions
|
@ -155,34 +155,8 @@ local function handle_certs()
|
|||
end
|
||||
end
|
||||
|
||||
function _M.call()
|
||||
if ngx.var.request_method ~= "POST" and ngx.var.request_method ~= "GET" then
|
||||
ngx.status = ngx.HTTP_BAD_REQUEST
|
||||
ngx.print("Only POST and GET requests are allowed!")
|
||||
return
|
||||
end
|
||||
|
||||
if ngx.var.request_uri == "/configuration/servers" then
|
||||
handle_servers()
|
||||
return
|
||||
end
|
||||
|
||||
if ngx.var.request_uri == "/configuration/general" then
|
||||
handle_general()
|
||||
return
|
||||
end
|
||||
|
||||
if ngx.var.uri == "/configuration/certs" then
|
||||
handle_certs()
|
||||
return
|
||||
end
|
||||
|
||||
if ngx.var.request_uri ~= "/configuration/backends" then
|
||||
ngx.status = ngx.HTTP_NOT_FOUND
|
||||
ngx.print("Not found!")
|
||||
return
|
||||
end
|
||||
|
||||
local function handle_backends()
|
||||
if ngx.var.request_method == "GET" then
|
||||
ngx.status = ngx.HTTP_OK
|
||||
ngx.print(_M.get_backends_data())
|
||||
|
@ -206,6 +180,37 @@ function _M.call()
|
|||
ngx.status = ngx.HTTP_CREATED
|
||||
end
|
||||
|
||||
function _M.call()
|
||||
if ngx.var.request_method ~= "POST" and ngx.var.request_method ~= "GET" then
|
||||
ngx.status = ngx.HTTP_BAD_REQUEST
|
||||
ngx.print("Only POST and GET requests are allowed!")
|
||||
return
|
||||
end
|
||||
|
||||
if ngx.var.request_uri == "/configuration/servers" then
|
||||
handle_servers()
|
||||
return
|
||||
end
|
||||
|
||||
if ngx.var.request_uri == "/configuration/general" then
|
||||
handle_general()
|
||||
return
|
||||
end
|
||||
|
||||
if ngx.var.uri == "/configuration/certs" then
|
||||
handle_certs()
|
||||
return
|
||||
end
|
||||
|
||||
if ngx.var.request_uri == "/configuration/backends" then
|
||||
handle_backends()
|
||||
return
|
||||
end
|
||||
|
||||
ngx.status = ngx.HTTP_NOT_FOUND
|
||||
ngx.print("Not found!")
|
||||
end
|
||||
|
||||
if _TEST then
|
||||
_M.handle_servers = handle_servers
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue