Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dario-piotrowicz/getbindingsproxy-poc-demo
https://github.com/dario-piotrowicz/getbindingsproxy-poc-demo
Last synced: 8 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/dario-piotrowicz/getbindingsproxy-poc-demo
- Owner: dario-piotrowicz
- Created: 2023-11-29T17:09:54.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2024-01-30T14:26:31.000Z (10 months ago)
- Last Synced: 2024-04-18T06:19:58.638Z (7 months ago)
- Language: TypeScript
- Size: 40 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# POC Demo for the new wrangler `getBindingsProxy` API
> [!note]
> This demo uses the wrangler prerelease generated in [workers-sdk#4523](https://github.com/cloudflare/workers-sdk/pull/4523)## The `getBindingsProxy` function
The function is used to get a proxy for the workerd bindings that can be then passed to user code
running in Nodejs processes. It spins up Miniflare under the hood and implements various logic (or reuses wrangle logic) that developers (or framework authors) would have to instead implement themselves.This utility allows anyone to easily get bindings that integrate well with wrangler without having to reinvent the wheel (such as reading the toml file and communicate with the wrangler local registry).
The function simply takes the bindings from a `wrangler.toml` file (for a current Workers setup), so in its simplest form, the function can be called without arguments:
```ts
const { bindings } = await getBindingsProxy();
```The returned `bindings` are simply the Miniflare bindings proxy returned to the user.
## Demo
In the `/demo` directory there is a single file that showcase the use of the function, `index.ts` which shows how the utility can be used.
To run the above, in the root directory of this repo, simply install the dependencies via:
```sh
pnpm i
```Then in a separate terminal start the do worker used to showcase local bindings:
```sh
pnpm start:do
```Once the two wrangler dev processes are ready then you can run the demo in a separate terminal:
```sh
pnpm start:demo
```
its output should showcase the bindings the demo gets access to:
```
MY_VARIABLE = production_value_from_toml# kv entries in MY_KV_FROM_TOML = 1
Message from do_worker = Hello from DurableObject!
```