0.6.3 • Published 2 years ago
cf-workers-proxy v0.6.3
cf-workers-proxy
Enable Cloudflare Workers runtime for local development. Compatible with DrizzleORM.
Get Started
Install wrangler
npm i -D wranglerInstall cf-workers-proxy
npm i -D cf-workers-proxyExample wrangler.toml
name = "worker"
compatibility_date = "2023-07-02"
[[d1_databases]]
binding = "D1"
database_name = "D1"
database_id = "<d1-id>"
[[kv_namespaces]]
binding = "KV"
id = "<kv-id>"
preview_id = "<same-kv-id-as-above>"
[[services]]
binding = "WORKER"
service = "<worker-name>"
environment = "production"Start proxy
npx wrangler node_modules/cf-workers-proxy/dist/worker.js --remoteExample SvelteKit project
// file: app.d.ts
declare global {
  namespace App {
    interface Locals {
      D1: D1Database;
    }
    interface Platform {
      env?: {
        D1: D1Database;
      };
    }
  }
}
export {};// file: src/hooks.server.ts
import { createD1 } from 'cf-workers-proxy';
export const handle = ({ event, resolve }) => {
  event.locals.D1 = event.platform?.env?.D1 ?? createD1('D1');
  // or createD1('D1', { hostname: 'custom-host-name' });
  // default hostname is `http://127.0.0.1:8787`
  return resolve(event);
};Roadmap
- ❌ Not started
 - 🟡 Partially implemented
 - ✅ Complete
 
D1Database
import { createD1 } from 'cf-workers-proxy';| Function | Status | 
|---|---|
prepare() | ✅ | 
batch() | ❌ | 
dump() | ❌ | 
exec() | ✅ | 
D1PreparedStatement
| Function | Status | 
|---|---|
first() | ✅ | 
run() | ✅ | 
all() | ✅ | 
raw() | ✅ | 
bind() | ✅ | 
Service Bindings
import { createServiceBinding } from 'cf-workers-proxy';| Function | Status | 
|---|---|
fetch() | ✅ | 
connect() | ❌ | 
KVNamespace
import { createKV } from 'cf-workers-proxy';| Function | Status | 
|---|---|
put() | 🟡 | 
get() | 🟡 | 
getWithMetadata() | ❌ | 
delete() | ❌ | 
list() | ❌ | 
waitUntil
// file: app.d.ts
namespace App {
  interface Platform {
    context: {
      waitUntil(promise: Promise<any>): void;
    };
  }
}// file: +page.server.ts
import { waitUntil } from 'cf-workers-proxy';
export const actions = {
  default: ({ locals, platform }) => {
    waitUntil(async () => {}, platform?.context.waitUntil);
    return { message: 'success' };
  },
};Contributing
or pull request 😐
0.5.10
2 years ago
0.5.11
2 years ago
0.5.8
2 years ago
0.5.7
2 years ago
0.5.9
2 years ago
0.1.0
2 years ago
0.3.0
2 years ago
0.2.0
2 years ago
0.6.3
2 years ago
0.5.4
2 years ago
0.6.2
2 years ago
0.5.3
2 years ago
0.5.6
2 years ago
0.5.5
2 years ago
0.5.0
2 years ago
0.4.0
2 years ago
0.6.1
2 years ago
0.5.2
2 years ago
0.6.0
2 years ago
0.5.1
2 years ago
0.0.5
2 years ago
0.0.4
2 years ago
0.0.3
2 years ago
0.0.2
2 years ago
0.0.1
2 years ago