Secret
A Cloudflare Secret creates an individual secret stored in a Secrets Store.
Basic Usage
Section titled “Basic Usage”import { Secret } from "alchemy/cloudflare";
const mySecret = await Secret("my-secret", { value: alchemy.secret(process.env.MY_SECRET),});
Then bind the Secret to your Worker:
export const worker = await Worker("worker", { bindings: { MY_SECRET: mySecret, },});
And use it at runtime:
import type { worker } from "../alchemy.run.ts";
export default { async fetch(request, env: typeof worker.Env) { const secret = await env.MY_SECRET.get();
// .. },};
Custom Secrets Store
Section titled “Custom Secrets Store”By default, the default_secrets_store
will be used, but you can also specify your own store.
import { Secret, SecretsStore } from "alchemy/cloudflare";
const store = await SecretsStore("my-store");
const mySecret = await Secret("my-secret", { store, value: alchemy.secret(process.env.MY_SECRET),});