updated cloudflare adapter docs to match new args

This commit is contained in:
dswbx
2025-01-25 12:33:05 +01:00
parent 475488c910
commit 1beac5043b
3 changed files with 19 additions and 19 deletions

View File

@@ -25,7 +25,6 @@ export async function getApi(Astro: TAstro, options: Options = { mode: "static"
let app: App; let app: App;
export function serve<Context extends TAstro = TAstro>(config: AstroBkndConfig<Context> = {}) { export function serve<Context extends TAstro = TAstro>(config: AstroBkndConfig<Context> = {}) {
return async (args: Context) => { return async (args: Context) => {
console.log("args", Object.keys(args));
if (!app) { if (!app) {
app = await createFrameworkApp(config, args); app = await createFrameworkApp(config, args);
} }

View File

@@ -16,11 +16,11 @@ and then install bknd as a dependency:
If you don't choose anything specific, the following code will use the `warm` mode. See the If you don't choose anything specific, the following code will use the `warm` mode. See the
chapter [Using a different mode](#using-a-different-mode) for available modes. chapter [Using a different mode](#using-a-different-mode) for available modes.
``` ts ```ts
import { serve } from "bknd/adapter/cloudflare"; import { serve } from "bknd/adapter/cloudflare";
export default serve({ export default serve<Env>({
app: (env: Env) => ({ app: ({ env }) => ({
connection: { connection: {
type: "libsql", type: "libsql",
config: { config: {
@@ -50,12 +50,12 @@ bucket = "node_modules/bknd/dist/static"
``` ```
And then modify the worker entry as follows: And then modify the worker entry as follows:
``` ts {2, 14, 15} ```ts {2, 14, 15}
import { serve } from "bknd/adapter/cloudflare"; import { serve } from "bknd/adapter/cloudflare";
import manifest from "__STATIC_CONTENT_MANIFEST"; import manifest from "__STATIC_CONTENT_MANIFEST";
export default serve({ export default serve<Env>({
app: (env: Env) => ({ app: ({ env }) => ({
connection: { connection: {
type: "libsql", type: "libsql",
config: { config: {
@@ -75,8 +75,8 @@ You can also add custom routes by defining them after the app has been built, li
import { serve } from "bknd/adapter/cloudflare"; import { serve } from "bknd/adapter/cloudflare";
import manifest from "__STATIC_CONTENT_MANIFEST"; import manifest from "__STATIC_CONTENT_MANIFEST";
export default serve({ export default serve<Env>({
app: (env: Env) => ({ app: ({ env }) => ({
connection: { connection: {
type: "libsql", type: "libsql",
config: { config: {
@@ -111,7 +111,7 @@ mode`, like so:
import { serve } from "bknd/adapter/cloudflare"; import { serve } from "bknd/adapter/cloudflare";
export default serve({ export default serve({
/* ... */, // ...
mode: "fresh" // mode: "fresh" | "warm" | "cache" | "durable" mode: "fresh" // mode: "fresh" | "warm" | "cache" | "durable"
}); });
``` ```
@@ -119,13 +119,14 @@ export default serve({
### Mode: `cache` ### Mode: `cache`
For the cache mode to work, you also need to specify the KV to be used. For this, use the For the cache mode to work, you also need to specify the KV to be used. For this, use the
`bindings` property: `bindings` property:
```ts ```ts
import { serve } from "bknd/adapter/cloudflare"; import { serve } from "bknd/adapter/cloudflare";
export default serve({ export default serve<Env>({
/* ... */, // ...
mode: "cache", mode: "cache",
bindings: (env: Env) => ({ kv: env.KV }) bindings: ({ env }) => ({ kv: env.KV })
}); });
``` ```
@@ -136,10 +137,10 @@ environment, and additionally export the `DurableBkndApp` class:
import { serve, DurableBkndApp } from "bknd/adapter/cloudflare"; import { serve, DurableBkndApp } from "bknd/adapter/cloudflare";
export { DurableBkndApp }; export { DurableBkndApp };
export default serve({ export default serve<Env>({
/* ... */, // ...
mode: "durable", mode: "durable",
bindings: (env: Env) => ({ dobj: env.DOBJ }), bindings: ({ env }) => ({ dobj: env.DOBJ }),
keepAliveSeconds: 60 // optional keepAliveSeconds: 60 // optional
}); });
``` ```
@@ -164,9 +165,9 @@ import type { App } from "bknd";
import { serve, DurableBkndApp } from "bknd/adapter/cloudflare"; import { serve, DurableBkndApp } from "bknd/adapter/cloudflare";
export default serve({ export default serve({
/* ... */, // ...
mode: "durable", mode: "durable",
bindings: (env: Env) => ({ dobj: env.DOBJ }), bindings: ({ env }) => ({ dobj: env.DOBJ }),
keepAliveSeconds: 60 // optional keepAliveSeconds: 60 // optional
}); });

View File

@@ -10,7 +10,7 @@ Install bknd as a dependency:
## Serve the API ## Serve the API
Create a new api splat route file at `app/routes/api.$.ts`: Create a new api splat route file at `app/routes/api.$.ts`:
``` tsx ```ts
// app/routes/api.$.ts // app/routes/api.$.ts
import { serve } from "bknd/adapter/remix"; import { serve } from "bknd/adapter/remix";