This package has been deprecated

Author message:

cf-workers-proxy has been renamed to wrangler-proxy, See https://github.com/chientrm/wrangler-proxy

cf-workers-proxy
TypeScript icon, indicating that this package has built-in type declarations

0.6.3 • Public • Published

cf-workers-proxy

Download Version

Enable Cloudflare Workers runtime for local development. Compatible with DrizzleORM.

Get Started

Install wrangler

npm i -D wrangler

Install cf-workers-proxy

npm i -D cf-workers-proxy

Example 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 --remote

Example 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

Buy Me A Coffee

or pull request 😐

Dependencies (0)

    Dev Dependencies (5)

    Package Sidebar

    Install

    npm i cf-workers-proxy

    Weekly Downloads

    1

    Version

    0.6.3

    License

    none

    Unpacked Size

    37.4 kB

    Total Files

    24

    Last publish

    Collaborators

    • chientrm