mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 04:27:21 +00:00
update docs on new cli starters
This commit is contained in:
@@ -5,7 +5,19 @@ 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:
|
||||||
|
|
||||||
|
<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 />
|
<InstallBknd />
|
||||||
|
|
||||||
<Note>The guide below assumes you're using Astro v4. We've experienced issues with Astro DB
|
<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
|
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).
|
out in [Discord](https://discord.gg/952SFk8Tb8) or open an [issue on GitHub](https://github.com/bknd-io/bknd/issues/new).
|
||||||
</Note>
|
</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`:
|
||||||
|
|||||||
@@ -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:
|
||||||
|
|
||||||
|
<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 />
|
<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
|
||||||
|
|||||||
@@ -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:
|
<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 />
|
<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:
|
||||||
|
|||||||
@@ -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:
|
||||||
|
|
||||||
|
<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 />
|
<InstallBknd />
|
||||||
|
</Tab>
|
||||||
|
</Tabs>
|
||||||
|
|
||||||
## Serve the API
|
## Serve the API
|
||||||
``` tsx
|
``` tsx
|
||||||
|
|||||||
@@ -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:
|
||||||
|
|
||||||
|
<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 />
|
<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"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -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:
|
||||||
|
|
||||||
|
<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 />
|
<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`:
|
||||||
|
|||||||
Reference in New Issue
Block a user