# register the registry access in accounts service (cookies should contain jwt) log_by_lua_block { local skynet_account = require("skynet.account") -- tracking runs only when request comes from authenticated user if skynet_account.is_authenticated() then local function track(premature, request_method, auth_headers) if premature then return end local httpc = require("resty.http").new() -- based on request method we assign a registry action string used -- in track endpoint namely "read" for GET and "write" for POST local registry_action = request_method == "GET" and "read" or "write" -- 10.10.10.70 points to accounts service (alias not available when using resty-http) local res, err = httpc:request_uri("http://10.10.10.70:3000/track/registry/" .. registry_action, { method = "POST", headers = auth_headers, }) if err or (res and res.status ~= ngx.HTTP_NO_CONTENT) then ngx.log(ngx.ERR, "Failed accounts service request /track/registry/" .. registry_action .. ": ", err or ("[HTTP " .. res.status .. "] " .. res.body)) end end if ngx.status == ngx.HTTP_OK or ngx.status == ngx.HTTP_NOT_FOUND then local ok, err = ngx.timer.at(0, track, ngx.req.get_method(), skynet_account.get_auth_headers()) if err then ngx.log(ngx.ERR, "Failed to create timer: ", err) end end end }