add internal endpoint for user info

This commit is contained in:
Karol Wypchlo 2021-04-08 12:36:04 +02:00
parent 26b3ec2cbc
commit 01e9ea57cc
1 changed files with 24 additions and 0 deletions

View File

@ -1,5 +1,11 @@
proxy_cache_path /data/nginx/cache levels=1:2 keys_zone=skynet:10m max_size=10g inactive=24h use_temp_path=off; proxy_cache_path /data/nginx/cache levels=1:2 keys_zone=skynet:10m max_size=10g inactive=24h use_temp_path=off;
# this runs before forking out nginx worker processes
init_by_lua_block {
require "cjson"
require "socket.http"
}
# ratelimit specified IPs # ratelimit specified IPs
geo $limit { geo $limit {
default 0; default 0;
@ -458,6 +464,24 @@ server {
proxy_pass http://127.0.0.1/$uri?attachment=true&$args; proxy_pass http://127.0.0.1/$uri?attachment=true&$args;
} }
location /__internal/do/not/use {
content_by_lua_block {
local json = require('cjson')
-- this block runs only when accounts are enabled
if os.getenv("ACCOUNTS_ENABLED", "0") == "0" then
return ngx.say(json.encode{authenticated = false})
end
local res = ngx.location.capture("/accounts/user/limits", { copy_all_vars = true })
if res.status == ngx.HTTP_OK then
local limits = json.decode(res.body)
return ngx.say(json.encode{authenticated = limits.tier > 0})
end
ngx.say(json.encode{authenticated = false})
}
}
location /accounts { location /accounts {
internal; # internal endpoint only internal; # internal endpoint only
access_log off; # do not log traffic access_log off; # do not log traffic