Skip to content

Commit

Permalink
worker.js
Browse files Browse the repository at this point in the history
  • Loading branch information
chientrm committed Aug 21, 2023
1 parent 6fadeec commit 86d041f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
8 changes: 8 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ build({
minify: true,
format: 'esm',
});

build({
entryPoints: ['worker.ts'],
outdir: 'dist',
bundle: true,
minify: true,
format: 'esm',
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cf-workers-proxy",
"description": "Enable Cloudflare Workers runtime for local development",
"description": "Enable Cloudflare Workers runtime for local development. Compatible with DrizzleORM",
"version": "0.0.1",
"type": "module",
"main": "dist/index.js",
Expand Down
15 changes: 8 additions & 7 deletions src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { D1DatabaseProxyHolder } from './proxies/d1_database/proxy_holder';
import { FetcherProxyHolder } from './proxies/fetcher/proxy_holder';
import { KVProxyHolder } from './proxies/kv/proxy_holder';

const json = <T>(data: T) => {
const defaultHostname = 'http://127.0.0.1:8787',
json = <T>(data: T) => {
const result: SuccessResult<T> = { status: 200, data },
response = new Response(JSON.stringify(result), {
headers: { 'Content-Type': 'application/json' },
Expand Down Expand Up @@ -44,24 +45,24 @@ const json = <T>(data: T) => {
return new Response(null, { status: 400 });
},
},
createD1 = (name: string, options?: { hostname?: string }): D1Database =>
createD1 = (name: string, options?: { hostname: string }): D1Database =>
new D1DatabaseProxyHolder({
host: options?.hostname ?? 'http://127.0.0.1:8787',
host: options?.hostname ?? defaultHostname,
name,
payload: {},
}),
createKV = (name: string, options?: { hostname?: string }): KVNamespace =>
createKV = (name: string, options?: { hostname: string }): KVNamespace =>
new KVProxyHolder({
host: options?.hostname ?? 'http://127.0.0.1:8787',
host: options?.hostname ?? defaultHostname,
name,
payload: {},
}),
createServiceBinding = (
name: string,
options?: { hostname?: string }
options?: { hostname: string }
): Fetcher =>
new FetcherProxyHolder({
host: options?.hostname ?? 'http://127.0.0.1:8787',
host: options?.hostname ?? defaultHostname,
name,
payload: {},
}),
Expand Down
3 changes: 3 additions & 0 deletions worker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { createWorker } from './src/worker';

export default createWorker();

0 comments on commit 86d041f

Please sign in to comment.