mirror of
https://github.com/bknd-io/bknd/
synced 2026-08-03 00:26:01 +00:00
removed durable mode as it requires an import from "cloudflare:" that often fails in non-cf environments
This commit is contained in:
@@ -170,3 +170,5 @@ dist
|
||||
|
||||
.dev.vars
|
||||
.wrangler/
|
||||
bknd-types.d.ts
|
||||
worker-configuration.d.ts
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* The configuration below is for advanced use cases. In order to enable types generation,
|
||||
* we need access to the database. However, for Cloudflare D1, we need the platform proxy.
|
||||
*
|
||||
* Since this configuration should serve all purposes, including usage within the worker itself,
|
||||
* we need to use an environment variable to determine if we need to extract the DB from proxy.
|
||||
*
|
||||
* To make D1 session work in the actual worker,
|
||||
*/
|
||||
|
||||
import { d1, registerMedia, type CloudflareBkndConfig } from "bknd/adapter/cloudflare";
|
||||
import type { PlatformProxy } from "wrangler";
|
||||
import process from "node:process";
|
||||
|
||||
const use_proxy = process.env.PROXY === "1";
|
||||
let proxy: PlatformProxy | undefined;
|
||||
|
||||
async function getEnv(env?: Env): Promise<Env> {
|
||||
if (use_proxy) {
|
||||
if (!proxy) {
|
||||
const getPlatformProxy = await import("wrangler").then((mod) => mod.getPlatformProxy);
|
||||
proxy = await getPlatformProxy();
|
||||
setTimeout(proxy?.dispose, 1000);
|
||||
}
|
||||
return proxy.env as unknown as Env;
|
||||
}
|
||||
return env!;
|
||||
}
|
||||
|
||||
export default {
|
||||
app: async (_env) => {
|
||||
if (!use_proxy) return {};
|
||||
const env = await getEnv(_env);
|
||||
return {
|
||||
connection: d1({
|
||||
binding: env.DB,
|
||||
}),
|
||||
};
|
||||
},
|
||||
beforeBuild: async (app, registries) => {
|
||||
if (!use_proxy) return;
|
||||
registerMedia(await getEnv(), registries);
|
||||
},
|
||||
d1: {
|
||||
session: true,
|
||||
},
|
||||
} satisfies CloudflareBkndConfig<Env>;
|
||||
@@ -2,10 +2,13 @@
|
||||
"name": "cloudflare-worker",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"deploy": "wrangler deploy",
|
||||
"dev": "wrangler dev",
|
||||
"typegen": "wrangler types"
|
||||
"bknd-typegen": "PROXY=1 npx bknd types",
|
||||
"typegen": "wrangler types && npm run bknd-typegen",
|
||||
"predev": "npm run typegen"
|
||||
},
|
||||
"dependencies": {
|
||||
"bknd": "file:../../app"
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
import { serve } from "bknd/adapter/cloudflare";
|
||||
import config from "../bknd.config";
|
||||
|
||||
export default serve({
|
||||
mode: "warm",
|
||||
d1: {
|
||||
session: true,
|
||||
},
|
||||
});
|
||||
export default serve(config);
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es2021",
|
||||
"lib": ["es2021"],
|
||||
"jsx": "react-jsx",
|
||||
"module": "es2022",
|
||||
"moduleResolution": "Bundler",
|
||||
"types": ["./worker-configuration.d.ts"],
|
||||
"lib": ["ES2022"],
|
||||
"target": "ES2022",
|
||||
"module": "ES2022",
|
||||
"moduleResolution": "bundler",
|
||||
"resolveJsonModule": true,
|
||||
"allowJs": true,
|
||||
"checkJs": false,
|
||||
@@ -18,5 +16,10 @@
|
||||
"skipLibCheck": true
|
||||
},
|
||||
"exclude": ["test"],
|
||||
"include": ["worker-configuration.d.ts", "src/**/*.ts"]
|
||||
"include": [
|
||||
"worker-configuration.d.ts",
|
||||
"bknd-types.d.ts",
|
||||
"bknd.config.ts",
|
||||
"src/**/*.ts"
|
||||
]
|
||||
}
|
||||
|
||||
+5751
-5
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user