Skip to content

Commit 30b1c95

Browse files
committed
📘 doc: cloudflare binding
1 parent ab79196 commit 30b1c95

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

docs/blog/elysia-14.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ const app = new Elysia()
142142
.post(
143143
'/user/:id',
144144
({ body }) => body,
145-
// ^?
145+
// ^?
146146

147147

148148

docs/integrations/cloudflare-worker.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,23 @@ Then you should be able to access your static file from the following path:
118118
- **http://localhost:8787/kyuukurarin.mp4**
119119
- **http://localhost:8787/static/mika.webp**
120120

121+
## Binding
122+
You can use a Cloudflare Workers binding by importing env from `cloudflare:workers`.
123+
124+
```ts
125+
import { Elysia } from 'elysia'
126+
import { CloudflareAdapter } from 'elysia/adapter/cloudflare-worker'
127+
import { env } from 'cloudflare:workers' // [!code ++]
128+
129+
export default new Elysia({
130+
adapter: CloudflareAdapter
131+
})
132+
.get('/', () => `Hello ${await env.KV.get('my-key')}`) // [!code ++]
133+
.compile()
134+
```
135+
136+
See [Cloudflare Workers: Binding](https://developers.cloudflare.com/workers/runtime-apis/bindings/#importing-env-as-a-global) for more information about binding.
137+
121138
## AoT compilation
122139
Previously, to use Elysia on Cloudflare Worker, you have to pass `aot: false` to the Elysia constructor.
123140

0 commit comments

Comments
 (0)