update docs on new cli starters

This commit is contained in:
dswbx
2025-02-19 21:27:04 +01:00
parent 89871a8ef7
commit eaa7276173
6 changed files with 144 additions and 57 deletions

View File

@@ -5,7 +5,19 @@ description: 'Run bknd inside Astro'
import InstallBknd from '/snippets/install-bknd.mdx';
## Installation
Install bknd as a dependency:
To get started with Astro and bknd you can either install the package manually, and follow the descriptions below, or use the CLI starter:
<Tabs>
<Tab title="CLI Starter">
Create a new Astro CLI starter project by running the following command:
```sh
npx bknd create -i astro
```
</Tab>
<Tab title="Manual">
Create a new Astro project by following the [official guide](https://docs.astro.build/en/install-and-setup/), and then install bknd as a dependency:
<InstallBknd />
<Note>The guide below assumes you're using Astro v4. We've experienced issues with Astro DB
@@ -33,6 +45,8 @@ export default defineConfig({
statically using Astro's middleware. In case you're interested in this, feel free to reach
out in [Discord](https://discord.gg/952SFk8Tb8) or open an [issue on GitHub](https://github.com/bknd-io/bknd/issues/new).
</Note>
</Tab>
</Tabs>
## Serve the API
Create a new catch-all route at `src/pages/api/[...api].ts`:

View File

@@ -5,8 +5,23 @@ description: 'Run bknd inside Bun'
import InstallBknd from '/snippets/install-bknd.mdx';
## Installation
Install bknd as a dependency:
To get started with Bun and bknd you can either install the package manually, and follow the descriptions below, or use the CLI starter:
<Tabs>
<Tab title="CLI Starter">
Create a new Bun CLI starter project by running the following command:
```sh
npx bknd create -i bun
```
</Tab>
<Tab title="Manual">
Create a new Bun project and then install bknd as a dependency:
<InstallBknd />
</Tab>
</Tabs>
## Serve the API & static files
The `serve` function of the Bun adapter makes sure to also serve the static files required for

View File

@@ -5,30 +5,51 @@ description: 'Run bknd inside Cloudflare Worker'
import InstallBknd from '/snippets/install-bknd.mdx';
## Installation
Create a new cloudflare worker project by following the
[official guide](https://developers.cloudflare.com/workers/get-started/guide/),
and then install bknd as a dependency:
To get started with Cloudflare Workers and bknd you can either install the package manually, and follow the descriptions below, or use the CLI starter:
<Tabs>
<Tab title="CLI Starter">
Create a new Cloudflare CLI starter project by running the following command:
```sh
npx bknd create -i cloudflare
```
</Tab>
<Tab title="Manual">
Create a new cloudflare worker project by following the [official guide](https://developers.cloudflare.com/workers/get-started/guide/), and then install bknd as a dependency:
<InstallBknd />
</Tab>
</Tabs>
## Serve the API
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 and uses the first D1 binding it finds. See the
chapter [Using a different mode](#using-a-different-mode) for available modes.
```ts src/index.ts
import { serve } from "bknd/adapter/cloudflare";
import { serve, d1 } from "bknd/adapter/cloudflare";
// scans your environment for the first D1 binding it finds
export default serve();
// manually specifying a D1 binding:
export default serve<Env>({
app: ({ env }) => ({
connection: {
url: env.DB_URL,
authToken: env.DB_TOKEN
}
})
app: ({ env }) => d1({ binding: env.D1_BINDING })
});
// or specify binding using `bindings`
export default serve<Env>({
bindings: ({ env }) => ({ db: env.D1_BINDING })
});
// or use LibSQL
export default serve<Env>({
app: ({ env }) => ({ url: env.DB_URL })
});
```
For more information about the connection object, refer to the [Database](/usage/database) guide.
For more information about the connection object when using LibSQL, refer to the [Database](/usage/database) guide.
Now run the worker:
```bash
@@ -73,24 +94,17 @@ Now in order to also server the static admin files, you have to modify the `wran
## Adding custom routes
You can also add custom routes by defining them after the app has been built, like so:
```ts {14-16}
```ts {5-7}
import { serve } from "bknd/adapter/cloudflare";
import manifest from "__STATIC_CONTENT_MANIFEST";
export default serve<Env>({
app: ({ env }) => ({
connection: {
url: env.DB_URL,
authToken: env.DB_TOKEN
}
}),
// ...
onBuilt: async (app) => {
app.modules.server.get("/hello", (c) => c.json({ hello: "world" }));
},
manifest,
setAdminHtml: true
app.server.get("/hello", (c) => c.json({ hello: "world" }));
}
});
```
The property `app.server` is a [Hono](https://hono.dev/) instance, you can literally anything you can do with Hono.
## Using a different mode
With the Cloudflare Workers adapter, you're being offered to 4 modes to choose from (default:

View File

@@ -5,8 +5,22 @@ description: 'Run bknd inside Next.js'
import InstallBknd from '/snippets/install-bknd.mdx';
## Installation
Install bknd as a dependency:
To get started with Next.js and bknd you can either install the package manually, and follow the descriptions below, or use the CLI starter:
<Tabs>
<Tab title="CLI Starter">
Create a new Next.js CLI starter project by running the following command:
```sh
npx bknd create -i nextjs
```
</Tab>
<Tab title="Manual">
Create a new Next.js project by following the [official guide](https://nextjs.org/docs/pages/api-reference/cli/create-next-app), and then install bknd as a dependency:
<InstallBknd />
</Tab>
</Tabs>
## Serve the API
``` tsx

View File

@@ -4,9 +4,24 @@ description: 'Run bknd inside Node'
---
import InstallBknd from '/snippets/install-bknd.mdx';
## Installation
Install bknd as a dependency:
To get started with Node and bknd you can either install the package manually, and follow the descriptions below, or use the CLI starter:
<Tabs>
<Tab title="CLI Starter">
Create a new Node CLI starter project by running the following command:
```sh
npx bknd create -i node
```
</Tab>
<Tab title="Manual">
Create a new Node project and then install bknd as a dependency:
<InstallBknd />
</Tab>
</Tabs>
## Serve the API & static files
The `serve` function of the Node adapter makes sure to also serve the static files required for
@@ -20,7 +35,7 @@ import { serve } from "bknd/adapter/node";
/** @type {import("bknd/adapter/node").NodeAdapterOptions} */
const config = {
connection: {
url: ":memory:"
url: "file:data.db"
}
};

View File

@@ -5,8 +5,23 @@ description: 'Run bknd inside Remix'
import InstallBknd from '/snippets/install-bknd.mdx';
## Installation
Install bknd as a dependency:
To get started with Remix and bknd you can either install the package manually, and follow the descriptions below, or use the CLI starter:
<Tabs>
<Tab title="CLI Starter">
Create a new Remix CLI starter project by running the following command:
```sh
npx bknd create -i remix
```
</Tab>
<Tab title="Manual">
Create a new Remix project by following the [official guide](https://remix.run/docs/en/main/other-api/create-remix), and then install bknd as a dependency:
<InstallBknd />
</Tab>
</Tabs>
## Serve the API
Since Remix doesn't support middleware yet, we need a helper file to initialize the App to import from. Create a new file at `app/bknd.ts`: