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.
Signature
Section titled “Signature”env_get(key)
syncParameters
Section titled “Parameters”| Param | Type | Description |
|---|---|---|
key |
string | Environment variable name (without SPYWEB_ prefix) |
Returns
Section titled “Returns”| Value | Type | Description |
|---|---|---|
| value | string / nil | Environment variable value, or nil if not set |
Example
Section titled “Example”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 requestendSee Also
Section titled “See Also”- before_fetch - Modify request before fetching