Skip to content

Latest commit

 

History

History
57 lines (39 loc) · 2.01 KB

File metadata and controls

57 lines (39 loc) · 2.01 KB
title Secrets
description Environment secrets are sensitive configuration settings, such as API keys, passwords, or tokens, that are securely stored and used by your script.

Environment secrets hold sensitive configuration values, such as API keys, passwords, or tokens. Your script reads them at runtime, so they never have to appear in your source code.

Unlike environment variables, secrets cannot be viewed once they are set. You can only update or delete them, which keeps the value hidden even from people with dashboard access.

Adding environment secrets

To add a secret to your script:

  1. Log in to the bunny.net dashboard.
  2. Select Edge Platform, click on Scripting, and select the script.

  1. Select Env Configuration and Environment Secrets, and fill in the details of the secret you want to create.

  1. Click Save Secret.

Using environment secrets

Environment secrets are accessed in the same way as environment variables, using either the Node.js process module or Deno.env.

import * as BunnySDK from "@bunny.net/edgescript-sdk";
import process from "node:process";

BunnySDK.net.http.serve(async (request: Request): Response | Promise<Response> => {
  // Load secret named ApiKey
  const apiKey = process.env.ApiKey;

  // Use the secret in an API request
  const response = await fetch("https://api.example.com/data", {
    headers: {
      "Authorization": `Bearer ${apiKey}`
    }
  });

  return new Response(await response.text());
});

You can also use Deno.env.get():

const apiKey = Deno.env.get("ApiKey");
Names of environment variables and secrets on the same script must be unique. You cannot use the same name for both a variable and a secret.