allow lua to use error pages

This commit is contained in:
Karol Wypchlo 2022-05-19 15:49:48 +02:00
parent 2f60d02131
commit 185daf6a08
No known key found for this signature in database
GPG Key ID: B515DE9EEBE241E1
3 changed files with 20 additions and 20 deletions

View File

@ -15,10 +15,10 @@ rewrite_by_lua_block {
-- 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
ngx.status = (hnsres_err and ngx.HTTP_INTERNAL_SERVER_ERROR) or hnsres_res.status
ngx.header["content-type"] = "text/plain"
ngx.say(hnsres_err or hnsres_res.body)
return ngx.exit(ngx.status)
-- ngx.status = (hnsres_err and ngx.HTTP_INTERNAL_SERVER_ERROR) or hnsres_res.status
-- ngx.header["content-type"] = "text/plain"
-- ngx.say(hnsres_err or hnsres_res.body)
return ngx.exit((hnsres_err and ngx.HTTP_INTERNAL_SERVER_ERROR) or hnsres_res.status)
end
-- 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
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.header["content-type"] = "text/plain"
ngx.say(registry_err or registry_res.body)
return ngx.exit(ngx.status)
-- ngx.status = (registry_err and ngx.HTTP_INTERNAL_SERVER_ERROR) or registry_res.status
-- ngx.header["content-type"] = "text/plain"
-- ngx.say(registry_err or registry_res.body)
return ngx.exit((registry_err and ngx.HTTP_INTERNAL_SERVER_ERROR) or registry_res.status)
end
-- since /skynet/registry endpoint response is a json, we need to decode it before we access it

View File

@ -23,10 +23,10 @@ location / {
ngx.var.skylink = match_skylink[1]
ngx.var.path = match_skylink[2] or "/"
else
ngx.status = (err and ngx.HTTP_INTERNAL_SERVER_ERROR) or res.status
ngx.header["content-type"] = "text/plain"
ngx.say(err or res.body)
ngx.exit(ngx.status)
-- ngx.status = (err and ngx.HTTP_INTERNAL_SERVER_ERROR) or res.status
-- ngx.header["content-type"] = "text/plain"
-- ngx.say(err or res.body)
ngx.exit((err and ngx.HTTP_INTERNAL_SERVER_ERROR) or res.status)
end
else
local resolved = cjson.decode(res.body)

View File

@ -44,18 +44,18 @@ end
-- handle request exit when access to portal should be restricted to authenticated users only
function _M.exit_access_unauthorized(message)
ngx.status = ngx.HTTP_UNAUTHORIZED
ngx.header["content-type"] = "text/plain"
ngx.say(message or "Portal operator restricted access to authenticated users only")
return ngx.exit(ngx.status)
-- ngx.status = ngx.HTTP_UNAUTHORIZED
-- ngx.header["content-type"] = "text/plain"
-- ngx.say(message or "Portal operator restricted access to authenticated users only")
return ngx.exit(ngx.HTTP_UNAUTHORIZED)
end
-- handle request exit when access to portal should be restricted to subscription users only
function _M.exit_access_forbidden(message)
ngx.status = ngx.HTTP_FORBIDDEN
ngx.header["content-type"] = "text/plain"
ngx.say(message or "Portal operator restricted access to users with active subscription only")
return ngx.exit(ngx.status)
-- ngx.status = ngx.HTTP_FORBIDDEN
-- ngx.header["content-type"] = "text/plain"
-- ngx.say(message or "Portal operator restricted access to users with active subscription only")
return ngx.exit(ngx.HTTP_FORBIDDEN)
end
function _M.accounts_enabled()