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,34 +5,48 @@ description: 'Run bknd inside Astro'
import InstallBknd from '/snippets/install-bknd.mdx'; import InstallBknd from '/snippets/install-bknd.mdx';
## Installation ## 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:
<InstallBknd />
<Note>The guide below assumes you're using Astro v4. We've experienced issues with Astro DB <Tabs>
using v5, see [this issue](https://github.com/withastro/astro/issues/12474).</Note> <Tab title="CLI Starter">
Create a new Astro CLI starter project by running the following command:
For the Astro integration to work, you also need to [add the react integration](https://docs.astro.build/en/guides/integrations-guide/react/): ```sh
```bash npx bknd create -i astro
npx astro add react ```
``` </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:
You also need to make sure to set the output to `hybrid` in your Astro config: <InstallBknd />
```js {6}
// astro.config.mjs
import { defineConfig } from "astro/config";
import react from "@astrojs/react";
export default defineConfig({ <Note>The guide below assumes you're using Astro v4. We've experienced issues with Astro DB
output: "hybrid", using v5, see [this issue](https://github.com/withastro/astro/issues/12474).</Note>
integrations: [react()]
});
```
<Note> For the Astro integration to work, you also need to [add the react integration](https://docs.astro.build/en/guides/integrations-guide/react/):
If you don't want to use React with Astro, there is also an option to serve the bknd Admin UI ```bash
statically using Astro's middleware. In case you're interested in this, feel free to reach npx astro add react
out in [Discord](https://discord.gg/952SFk8Tb8) or open an [issue on GitHub](https://github.com/bknd-io/bknd/issues/new). ```
</Note>
You also need to make sure to set the output to `hybrid` in your Astro config:
```js {6}
// astro.config.mjs
import { defineConfig } from "astro/config";
import react from "@astrojs/react";
export default defineConfig({
output: "hybrid",
integrations: [react()]
});
```
<Note>
If you don't want to use React with Astro, there is also an option to serve the bknd Admin UI
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 ## Serve the API
Create a new catch-all route at `src/pages/api/[...api].ts`: 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'; import InstallBknd from '/snippets/install-bknd.mdx';
## Installation ## 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:
<InstallBknd />
<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 ## Serve the API & static files
The `serve` function of the Bun adapter makes sure to also serve the static files required for 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'; import InstallBknd from '/snippets/install-bknd.mdx';
## Installation ## Installation
Create a new cloudflare worker project by following the 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:
[official guide](https://developers.cloudflare.com/workers/get-started/guide/),
and then install bknd as a dependency:
<InstallBknd /> <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 ## 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. chapter [Using a different mode](#using-a-different-mode) for available modes.
```ts src/index.ts ```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>({ export default serve<Env>({
app: ({ env }) => ({ app: ({ env }) => d1({ binding: env.D1_BINDING })
connection: { });
url: env.DB_URL,
authToken: env.DB_TOKEN // 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: Now run the worker:
```bash ```bash
@@ -73,24 +94,17 @@ Now in order to also server the static admin files, you have to modify the `wran
## Adding custom routes ## Adding custom routes
You can also add custom routes by defining them after the app has been built, like so: 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 { serve } from "bknd/adapter/cloudflare";
import manifest from "__STATIC_CONTENT_MANIFEST";
export default serve<Env>({ export default serve<Env>({
app: ({ env }) => ({ // ...
connection: {
url: env.DB_URL,
authToken: env.DB_TOKEN
}
}),
onBuilt: async (app) => { onBuilt: async (app) => {
app.modules.server.get("/hello", (c) => c.json({ hello: "world" })); app.server.get("/hello", (c) => c.json({ hello: "world" }));
}, }
manifest,
setAdminHtml: true
}); });
``` ```
The property `app.server` is a [Hono](https://hono.dev/) instance, you can literally anything you can do with Hono.
## Using a different mode ## Using a different mode
With the Cloudflare Workers adapter, you're being offered to 4 modes to choose from (default: 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'; import InstallBknd from '/snippets/install-bknd.mdx';
## Installation ## 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:
<InstallBknd />
<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 ## Serve the API
``` tsx ``` tsx

View File

@@ -4,9 +4,24 @@ description: 'Run bknd inside Node'
--- ---
import InstallBknd from '/snippets/install-bknd.mdx'; import InstallBknd from '/snippets/install-bknd.mdx';
## Installation ## 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:
<InstallBknd />
<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 ## Serve the API & static files
The `serve` function of the Node adapter makes sure to also serve the static files required for 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} */ /** @type {import("bknd/adapter/node").NodeAdapterOptions} */
const config = { const config = {
connection: { 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'; import InstallBknd from '/snippets/install-bknd.mdx';
## Installation ## 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:
<InstallBknd />
<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 ## 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`: 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`: