Skip to content

Commit

Permalink
docs: update cloudflare docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Hebilicious committed Aug 7, 2023
1 parent bcc3e40 commit 3c0b64b
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions docs/content/2.deploy/providers/cloudflare.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Deploy Nitro apps to CloudFlare.
::

::alert{type="warning"}
**Warning:** Please be aware that `runtimeConfig` cannot be updated via Cloudflare's environment variables (see [#272](https://github.com/unjs/nitro/issues/272) for more). As a workaround, you can use the Cloudflare env variables as constants in the code, or the module syntax.
**Warning:** Cloudflare environment variables are only available within event handlers with `useRuntimeConfig(event)`. You can also access environment variables as globals in the `cloudflare` preset, and with `event.context.env` in the`cloudflare_module` and `cloudflare_page` presets.
::

Login to your [Cloudflare Workers](https://workers.cloudflare.com) account and obtain your `account_id` from the sidebar.
Expand Down Expand Up @@ -223,7 +223,7 @@ const stmt = await cloudflare.env.D1.prepare('SELECT id FROM table')
const { results } = await stmt.all()
```

### Environment variables and secrets
## Environment variables and secrets

You can add environment variables and secret to your project and they will be accessible within your event handlers.
You can acess them with `event.cloudflare.env`.
Expand All @@ -236,22 +236,18 @@ When you try out your project locally with `wrangler dev` or `wrangler pages dev

For production, use the cloudflare dashboard or the [`wrangler secret`](https://developers.cloudflare.com/workers/wrangler/commands/#secret) command to set environment variables and secrets.

#### useRuntimeConfig
### useRuntimeConfig

For your convenience, the `useRuntimeConfig` helper will return a `camelCase` version of your custom cloudflare environment variables and secrets.

::alert{type="info"}
**Note:** Only the variables prefixed with `NITRO_` or `NUXT` will be applied to `useRuntimeConfig`, and they will override the variables defined within `nitro.options.runtimeConfig`.
::

```bash
NITRO_HELLO="world"
NUXT_HELLO_THERE="general"
SECRET="secret"
```

::alert{type="info"}
**Note:** Cloudflare variables are only available within event handlers with `useRuntimeConfig(event)`.
**Note:** Only the variables prefixed with `NITRO_` or `NUXT` will be applied to `useRuntimeConfig`, and they will override the variables defined within `nitro.options.runtimeConfig`.
::

```ts
Expand All @@ -265,7 +261,7 @@ export default defineEventHandler((event) => {
});
```

#### wrangler.toml
### wrangler.toml

You can specify a custom `wrangler.toml` file and define vars inside.
Note that this isn't recommend for sensitive data.
Expand Down

0 comments on commit 3c0b64b

Please sign in to comment.