cf-bindings-proxy v0.7.1
This library was written to accompany @cloudflare/next-on-pages
, so that you can use bindings when developing Next.js apps locally through next dev
.
It is intended to be used for frameworks that do not support Cloudflare bindings in a fast HMR environment.
Usage
import { binding } from 'cf-bindings-proxy';
const value = await binding<KVNamespace>('MY_KV').get('key');
How It Works
Starting the proxy spawns an instance of Wrangler using a template, passing through any commands and bindings that are supplied to the CLI. It uses port 8799
.
In development mode, when interacting with a binding through the binding('BINDING_NAME')
function, it sends HTTP requests to the proxy. These HTTP requests contain destructured function calls, which are then reconstructed and executed inside the proxy. The result is then returned to the client.
When building for production, binding('BINDING_NAME')
simply calls process.env.BINDING_NAME
to retrieve the binding instead.
When It's Active
Calls to binding('BINDING_NAME')
will try to use the proxy when either of the following two conditions are met:
- The
ENABLE_BINDINGS_PROXY
environment variable is set totrue
. OR - The
DISABLE_BINDINGS_PROXY
environment variable is not set andNODE_ENV
is set todevelopment
.
Supported
Note: Functionality and bindings not listed below may still work but have not been tested.
KV
- put
- get
- list
- getWithMetadata
- delete
D1
- prepare
- bind
- run
- all
- first
- raw
- batch
- exec
- dump
R2
- put
- writeHttpMetadata
- get
- writeHttpMetadata
- text
- json
- arrayBuffer
- blob
- body
- bodyUsed
- head
- writeHttpMetadata
- list
- writeHttpMetadata
- delete
- createMultipartUpload
- resumeMultipartUpload
9 months ago
9 months ago
9 months ago
8 months ago
9 months ago
9 months ago
10 months ago
9 months ago
10 months ago
9 months ago
10 months ago
9 months ago
9 months ago
8 months ago
10 months ago
9 months ago
7 months ago
9 months ago
9 months ago
9 months ago
9 months ago
8 months ago
9 months ago
9 months ago
9 months ago
9 months ago
8 months ago
9 months ago
10 months ago
10 months ago
9 months ago
9 months ago
7 months ago
10 months ago
9 months ago
9 months ago
7 months ago
9 months ago
9 months ago
10 months ago
9 months ago
9 months ago
10 months ago
9 months ago
9 months ago
10 months ago
8 months ago
10 months ago
10 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago