fix response

This commit is contained in:
Karol Wypchlo 2021-04-08 12:57:15 +02:00
parent c8e87bf2ba
commit 3021032464
1 changed files with 11 additions and 2 deletions

View File

@ -465,20 +465,29 @@ server {
} }
location /__internal/do/not/use { location /__internal/do/not/use {
include /etc/nginx/conf.d/include/cors;
charset utf-8;
charset_types application/json;
default_type application/json;
content_by_lua_block { content_by_lua_block {
local json = require('cjson') local json = require('cjson')
-- this block runs only when accounts are enabled -- this block runs only when accounts are enabled
if os.getenv("ACCOUNTS_ENABLED", "0") == "0" then if os.getenv("ACCOUNTS_ENABLED", "0") == "0" then
return ngx.say(json.encode{authenticated = false}) ngx.say(json.encode{authenticated = false})
return ngx.exit(ngx.HTTP_OK)
end end
local res = ngx.location.capture("/accounts/user", { copy_all_vars = true }) local res = ngx.location.capture("/accounts/user", { copy_all_vars = true })
if res.status == ngx.HTTP_OK then if res.status == ngx.HTTP_OK then
local limits = json.decode(res.body) local limits = json.decode(res.body)
return ngx.say(json.encode{authenticated = limits.tier > 0}) ngx.say(json.encode{authenticated = limits.tier > 0})
return ngx.exit(ngx.HTTP_OK)
end end
ngx.say(json.encode{authenticated = false}) ngx.say(json.encode{authenticated = false})
return ngx.exit(ngx.HTTP_OK)
} }
} }