Documentation Index
Fetch the complete documentation index at: https://docs.bunny.net/llms.txt
Use this file to discover all available pages before exploring further.
Environment variables are used to store information or configuration data that your script requires at runtime. They enable you to manage any values separate from the script code. This separation ensures that variable values are not exposed and stored in your scripts or version control systems but rather configured in the runtime.
For sensitive data such as API keys, passwords, or tokens, use environment
secrets instead. Secrets are encrypted and cannot be
viewed once set.
Adding environment variables
To add environment variables to your script, follow these steps:
- Log in to the bunny.net dashboard.
- Select Edge Platform, click on Scripting, and select the script.
- Select Env Configuration and Environment Variables, and fill in the details of the variable you want to create.
- Click Save.
Using environment variables
You can access environment variable value in the script code using node process module or using Deno.env.
The following script example shows how to access an environment variable value using node process module:
import * as BunnySDK from "@bunny.net/edgescript-sdk";
import process from "node:process";
BunnySDK.net.http.serve(
async (request: Request): Response | Promise<Response> => {
// Load environment variable named OriginUrl
const originUrl = process.env.OriginUrl;
// Parse initial url
const url = new URL(request.url);
// Rewrite and fetch request from origin
return fetch(originUrl + url.pathname);
},
);
The following script example shows script code with same logic but using Deno.env to access variable value:
import * as BunnySDK from "@bunny.net/edgescript-sdk";
BunnySDK.net.http.serve(
async (request: Request): Response | Promise<Response> => {
// Load environment variable named OriginUrl
const originUrl = Deno.env.get("OriginUrl");
// Parse initial url
const url = new URL(request.url);
// Rewrite and fetch request from origin
return fetch(originUrl + url.pathname);
},
);