feat: improve logging in access.lua

This commit is contained in:
Iain Learmonth 2025-04-28 15:35:00 +01:00
parent 19adda03d9
commit 09b178dca8

View file

@ -7,6 +7,7 @@ local utils = require "utils"
local jasima_host = config.get_jasima_host()
ngx.ctx.jasima_host = jasima_host
if not jasima_host then
ngx.log(ngx.DEBUG, "no host specified via header or cookie")
return ngx.exit(400)
end
@ -14,29 +15,33 @@ local err
ngx.ctx.jasima_config, err = config.load_config(jasima_host)
if err then
ngx.status = 500
ngx.log(ngx.ERR, "Could not load config: " .. err)
ngx.log(ngx.ERR, "could not load config: " .. err)
return ngx.exit(500)
end
if not ngx.ctx.jasima_config then
ngx.status = 403
ngx.log(ngx.ERR, "Requested a canonical host that has no configuration specified: " .. jasima_host)
ngx.log(ngx.INFO, "requested a canonical host that has no configuration specified: " .. jasima_host)
ngx.exit(403)
end
local country = geo.viewer_country()
if not ngx.ctx.jasima_config.geo_redirect_disable and not geo.needs_mirror(country) then
if not ngx.ctx.jasima_config.geo_redirect_disable then
ngx.log(ngx.DEBUG, "geo_redirect_disable not configured for site " .. jasima_host)
if not geo.needs_mirror(country) then
ngx.log(ngx.DEBUG, "mirror is not needed for viewer in " .. country .. " for " .. jasima_host .. ", redirecting")
local request_uri = ngx.var.request_uri
local new_url = "https://" .. jasima_host .. request_uri
return ngx.redirect(new_url, ngx.HTTP_MOVED_TEMPORARILY)
end
end
-- Get jasima_pool (not critical)
local jasima_pool = config.get_jasima_pool()
ngx.ctx.jasima_pool_map, err = config.load_pool_mapping(jasima_pool)
if err then
ngx.status = 500
ngx.log(ngx.WARN, "Could not load pool mapping: " .. err)
ngx.log(ngx.WARN, "could not load requested pool mapping: " .. err)
return ngx.exit(500)
end