Cloudflare Workers (CLI Integration)

Use your Onboardbase managed secrets on Cloudflare workers

You can push your secrets from Onboardbase into your Cloudflare worker with the help of Onboardbase CLI secret command and Cloudflare's wrangler secret command.

Ensure that you have installed, logged in, and set up Onboardbase project in your Cloudflare workers project. You can do these from the setup here.

Download your secrets in JSON

Run onboardbase secrets:download --json

This would generate an onboardbase.json file which contains a JSON of key/value for the project and secret that has been set up in the .onboardbase.yamlfile in the root of your project.

Upload your secrets to your workers K/V secrets

Run npx wrangler secrets:bulk ./onboardbase.json

This would take the secrets downloaded above and upload them to your Cloudflare worker key/value secrets.

See Wrangler Bulk Secrets for more information.

Confirm this operation by going into the settings page of your worker on Cloudflare and clicking on the variables tab

Use your secrets in your worker

In your index.ts file, add the secret that you require in the Env interface, then in your code with the env variable access the env using the dot operator and then the key name

export interface Env {
  HI: string;

export default {
  async fetch(
    request: Request,
    env: Env,
    ctx: ExecutionContext
  ): Promise<Response> {
    return new Response(`Secret value for HI = ${env.HI}`);

Run yarn start or npm start to start the development server.

You should have the value for the variable HI referenced in the output HTML