Skip to main content
Version: v0.x

How do I use environment variables?

You might want to set environment variables and secrets in Proxyflare. Wrapping Proxyflare in a PagesFunction provides access to a Context with environment variables on ctx.env.

Environment variables can be managed from your Cloudflare Pages dashboard.

import proxyflare from "@flaregun-net/proxyflare-for-pages"

const routes: Route[] = []

// Set API_SERVICE_TOKEN in your Pages dashboard.
type Env = { API_SERVICE_TOKEN: string }

export const onRequest: PagesFunction<Env>[] = [
(ctx) =>
config: {
routes: [
from: { pattern: "*" },
to: { url: "" },
headers: {
request: `Bearer ${ctx.env.API_SERVICE_TOKEN}`,

Refer to the Cloudflare docs to learn more about environment variables best practices.