Platforms
Envlet on Cloudflare Workers
Workers have no process.env, so pass the token from your binding to load() and read the returned values.
Set the token
wrangler secret put ENVLET_TOKENLoad in the handler
import { load } from "@envlet/sdk";
export default {
async fetch(request: Request, env: { ENVLET_TOKEN: string }) {
const values = await load({ token: env.ENVLET_TOKEN });
return new Response(values.APP_NAME);
},
};Set up
- 01
Create a token
Create an identity for Cloudflare Workers and a token for the environment it deploys.
- 02
Set one secret
wrangler secret put stores ENVLET_TOKEN as a Worker secret. Use a different token per environment in wrangler.jsonc env blocks.
- 03
Start through Envlet
Call load() with the token from env inside the handler. Cache the promise per isolate if you want one fetch per cold start.
Questions
- Will my app start if Envlet is down?
- No, and that is the point. It retries for a few seconds, then fails so you notice, instead of starting with half an environment.
- Do I still need Cloudflare Workers's own secret store?
- Only for ENVLET_TOKEN. Everything else lives in Envlet, so you rotate in one place.