allow lua to use error pages
This commit is contained in:
parent
2f60d02131
commit
185daf6a08
|
@ -15,10 +15,10 @@ rewrite_by_lua_block {
|
||||||
|
|
||||||
-- print error and exit with 500 or exit with response if status is not 200
|
-- print error and exit with 500 or exit with response if status is not 200
|
||||||
if hnsres_err or (hnsres_res and hnsres_res.status ~= ngx.HTTP_OK) then
|
if hnsres_err or (hnsres_res and hnsres_res.status ~= ngx.HTTP_OK) then
|
||||||
ngx.status = (hnsres_err and ngx.HTTP_INTERNAL_SERVER_ERROR) or hnsres_res.status
|
-- ngx.status = (hnsres_err and ngx.HTTP_INTERNAL_SERVER_ERROR) or hnsres_res.status
|
||||||
ngx.header["content-type"] = "text/plain"
|
-- ngx.header["content-type"] = "text/plain"
|
||||||
ngx.say(hnsres_err or hnsres_res.body)
|
-- ngx.say(hnsres_err or hnsres_res.body)
|
||||||
return ngx.exit(ngx.status)
|
return ngx.exit((hnsres_err and ngx.HTTP_INTERNAL_SERVER_ERROR) or hnsres_res.status)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- since /hnsres endpoint response is a json, we need to decode it before we access it
|
-- since /hnsres endpoint response is a json, we need to decode it before we access it
|
||||||
|
@ -48,10 +48,10 @@ rewrite_by_lua_block {
|
||||||
|
|
||||||
-- print error and exit with 500 or exit with response if status is not 200
|
-- print error and exit with 500 or exit with response if status is not 200
|
||||||
if registry_err or (registry_res and registry_res.status ~= ngx.HTTP_OK) then
|
if registry_err or (registry_res and registry_res.status ~= ngx.HTTP_OK) then
|
||||||
ngx.status = (registry_err and ngx.HTTP_INTERNAL_SERVER_ERROR) or registry_res.status
|
-- ngx.status = (registry_err and ngx.HTTP_INTERNAL_SERVER_ERROR) or registry_res.status
|
||||||
ngx.header["content-type"] = "text/plain"
|
-- ngx.header["content-type"] = "text/plain"
|
||||||
ngx.say(registry_err or registry_res.body)
|
-- ngx.say(registry_err or registry_res.body)
|
||||||
return ngx.exit(ngx.status)
|
return ngx.exit((registry_err and ngx.HTTP_INTERNAL_SERVER_ERROR) or registry_res.status)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- since /skynet/registry endpoint response is a json, we need to decode it before we access it
|
-- since /skynet/registry endpoint response is a json, we need to decode it before we access it
|
||||||
|
|
|
@ -23,10 +23,10 @@ location / {
|
||||||
ngx.var.skylink = match_skylink[1]
|
ngx.var.skylink = match_skylink[1]
|
||||||
ngx.var.path = match_skylink[2] or "/"
|
ngx.var.path = match_skylink[2] or "/"
|
||||||
else
|
else
|
||||||
ngx.status = (err and ngx.HTTP_INTERNAL_SERVER_ERROR) or res.status
|
-- ngx.status = (err and ngx.HTTP_INTERNAL_SERVER_ERROR) or res.status
|
||||||
ngx.header["content-type"] = "text/plain"
|
-- ngx.header["content-type"] = "text/plain"
|
||||||
ngx.say(err or res.body)
|
-- ngx.say(err or res.body)
|
||||||
ngx.exit(ngx.status)
|
ngx.exit((err and ngx.HTTP_INTERNAL_SERVER_ERROR) or res.status)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local resolved = cjson.decode(res.body)
|
local resolved = cjson.decode(res.body)
|
||||||
|
|
|
@ -44,18 +44,18 @@ end
|
||||||
|
|
||||||
-- handle request exit when access to portal should be restricted to authenticated users only
|
-- handle request exit when access to portal should be restricted to authenticated users only
|
||||||
function _M.exit_access_unauthorized(message)
|
function _M.exit_access_unauthorized(message)
|
||||||
ngx.status = ngx.HTTP_UNAUTHORIZED
|
-- ngx.status = ngx.HTTP_UNAUTHORIZED
|
||||||
ngx.header["content-type"] = "text/plain"
|
-- ngx.header["content-type"] = "text/plain"
|
||||||
ngx.say(message or "Portal operator restricted access to authenticated users only")
|
-- ngx.say(message or "Portal operator restricted access to authenticated users only")
|
||||||
return ngx.exit(ngx.status)
|
return ngx.exit(ngx.HTTP_UNAUTHORIZED)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- handle request exit when access to portal should be restricted to subscription users only
|
-- handle request exit when access to portal should be restricted to subscription users only
|
||||||
function _M.exit_access_forbidden(message)
|
function _M.exit_access_forbidden(message)
|
||||||
ngx.status = ngx.HTTP_FORBIDDEN
|
-- ngx.status = ngx.HTTP_FORBIDDEN
|
||||||
ngx.header["content-type"] = "text/plain"
|
-- ngx.header["content-type"] = "text/plain"
|
||||||
ngx.say(message or "Portal operator restricted access to users with active subscription only")
|
-- ngx.say(message or "Portal operator restricted access to users with active subscription only")
|
||||||
return ngx.exit(ngx.status)
|
return ngx.exit(ngx.HTTP_FORBIDDEN)
|
||||||
end
|
end
|
||||||
|
|
||||||
function _M.accounts_enabled()
|
function _M.accounts_enabled()
|
||||||
|
|
Reference in New Issue