Skip to content

env_get

env_get(key) retrieves a read-only environment variable from the host system. Automatically prepends the SPYWEB_ prefix for security, allowing you to store secrets outside config files.

env_get(key)
sync
Param Type Description
key string Environment variable name (without SPYWEB_ prefix)
Value Type Description
value string / nil Environment variable value, or nil if not set
function before_fetch(request, ctx)
local api_key = env_get("API_KEY") -- Reads SPYWEB_API_KEY
if api_key then
request.headers["Authorization"] = "Bearer " .. api_key
end
return request
end