From 185daf6a08ba737513f0ae8e30821d5dd0c58165 Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Thu, 19 May 2022 15:49:48 +0200 Subject: [PATCH] allow lua to use error pages --- docker/nginx/conf.d/include/location-hns | 16 ++++++++-------- docker/nginx/conf.d/server/server.dnslink | 8 ++++---- docker/nginx/libs/skynet/account.lua | 16 ++++++++-------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/docker/nginx/conf.d/include/location-hns b/docker/nginx/conf.d/include/location-hns index 0ddb62d7..33bbd915 100644 --- a/docker/nginx/conf.d/include/location-hns +++ b/docker/nginx/conf.d/include/location-hns @@ -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 diff --git a/docker/nginx/conf.d/server/server.dnslink b/docker/nginx/conf.d/server/server.dnslink index 139196ef..b5eaefe5 100644 --- a/docker/nginx/conf.d/server/server.dnslink +++ b/docker/nginx/conf.d/server/server.dnslink @@ -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) diff --git a/docker/nginx/libs/skynet/account.lua b/docker/nginx/libs/skynet/account.lua index 709d8130..958e1297 100644 --- a/docker/nginx/libs/skynet/account.lua +++ b/docker/nginx/libs/skynet/account.lua @@ -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()