mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 12:37:20 +00:00
public commit
This commit is contained in:
40
docs/integration/bun.mdx
Normal file
40
docs/integration/bun.mdx
Normal file
@@ -0,0 +1,40 @@
|
||||
---
|
||||
title: 'Bun'
|
||||
description: 'Run bknd inside Bun'
|
||||
---
|
||||
import InstallBknd from '/snippets/install-bknd.mdx';
|
||||
|
||||
## Installation
|
||||
Install bknd as a dependency:
|
||||
<InstallBknd />
|
||||
|
||||
## Serve the API & static files
|
||||
The `serve` function of the Bun adapter makes sure to also serve the static files required for
|
||||
the admin panel.
|
||||
|
||||
``` tsx
|
||||
// index.ts
|
||||
import { serve } from "bknd/adapter/bun";
|
||||
|
||||
const handler = serve({
|
||||
connection: {
|
||||
type: "libsql",
|
||||
config: {
|
||||
url: process.env.DB_URL!,
|
||||
authToken: process.env.DB_AUTH_TOKEN!
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Bun.serve({
|
||||
port: 1337,
|
||||
fetch: handler
|
||||
});
|
||||
|
||||
console.log("Server running at http://localhost:1337");
|
||||
```
|
||||
|
||||
Run the application using Bun by executing:
|
||||
```bash
|
||||
bun run index.ts
|
||||
```
|
||||
96
docs/integration/cloudflare.mdx
Normal file
96
docs/integration/cloudflare.mdx
Normal file
@@ -0,0 +1,96 @@
|
||||
---
|
||||
title: 'Cloudflare'
|
||||
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:
|
||||
|
||||
<InstallBknd />
|
||||
|
||||
## Serve the API
|
||||
|
||||
``` ts
|
||||
import { serve } from "bknd/adapter/cloudflare";
|
||||
|
||||
export default serve(
|
||||
{
|
||||
app: (env: Env) => ({
|
||||
connection: {
|
||||
type: "libsql",
|
||||
config: {
|
||||
url: env.DB_URL,
|
||||
authToken: env.DB_TOKEN
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
);
|
||||
```
|
||||
|
||||
Now run the worker:
|
||||
```bash
|
||||
wrangler dev
|
||||
```
|
||||
|
||||
And confirm it works by opening [http://localhost:8787](http://localhost:8787) in
|
||||
your browser.
|
||||
|
||||
## Serve the Admin UI
|
||||
Now in order to also server the static admin files, you have to modify the `wrangler.toml` to
|
||||
include the static assets:
|
||||
```toml
|
||||
[site]
|
||||
bucket = "node_modules/bknd/dist/static"
|
||||
```
|
||||
|
||||
And then modify the worker entry as follows:
|
||||
``` ts {2, 15, 17}
|
||||
import { serve } from "bknd/adapter/cloudflare";
|
||||
import manifest from "__STATIC_CONTENT_MANIFEST";
|
||||
|
||||
export default serve(
|
||||
{
|
||||
app: (env: Env) => ({
|
||||
connection: {
|
||||
type: "libsql",
|
||||
config: {
|
||||
url: env.DB_URL,
|
||||
authToken: env.DB_TOKEN
|
||||
}
|
||||
}
|
||||
}),
|
||||
setAdminHtml: true
|
||||
},
|
||||
manifest
|
||||
);
|
||||
```
|
||||
|
||||
## Adding custom routes
|
||||
You can also add custom routes by defining them after the app has been built, like so:
|
||||
```ts {15-17}
|
||||
import { serve } from "bknd/adapter/cloudflare";
|
||||
import manifest from "__STATIC_CONTENT_MANIFEST";
|
||||
|
||||
export default serve(
|
||||
{
|
||||
app: (env: Env) => ({
|
||||
connection: {
|
||||
type: "libsql",
|
||||
config: {
|
||||
url: env.DB_URL,
|
||||
authToken: env.DB_TOKEN
|
||||
}
|
||||
}
|
||||
}),
|
||||
onBuilt: async (app) => {
|
||||
app.modules.server.get("/hello", (c) => c.json({ hello: "world" }));
|
||||
},
|
||||
setAdminHtml: true
|
||||
},
|
||||
manifest
|
||||
);
|
||||
```
|
||||
57
docs/integration/nextjs.mdx
Normal file
57
docs/integration/nextjs.mdx
Normal file
@@ -0,0 +1,57 @@
|
||||
---
|
||||
title: 'Next.js'
|
||||
description: 'Run bknd inside Next.js'
|
||||
---
|
||||
import InstallBknd from '/snippets/install-bknd.mdx';
|
||||
|
||||
<Note>
|
||||
Next.js support is currently experimental, this guide only covers adding bknd using `pages`
|
||||
folder.
|
||||
</Note>
|
||||
|
||||
## Installation
|
||||
Install bknd as a dependency:
|
||||
<InstallBknd />
|
||||
|
||||
## Serve the API
|
||||
``` tsx
|
||||
// pages/api/[...route].ts
|
||||
import { serve } from "bknd/adapter/nextjs";
|
||||
import type { PageConfig } from "next";
|
||||
|
||||
export const config: PageConfig = {
|
||||
runtime: "edge"
|
||||
};
|
||||
|
||||
export default serve({
|
||||
connection: {
|
||||
type: "libsql",
|
||||
config: {
|
||||
url: process.env.DB_URL!,
|
||||
authToken: process.env.DB_AUTH_TOKEN!
|
||||
}
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
## Enabling the Admin UI
|
||||
Create a file `[[...admin]].tsx` inside the `pages/admin` folder:
|
||||
```tsx
|
||||
// pages/admin/[[...admin]].tsx
|
||||
import type { PageConfig } from "next";
|
||||
import dynamic from "next/dynamic";
|
||||
import "bknd/dist/styles.css";
|
||||
|
||||
export const config: PageConfig = {
|
||||
runtime: "experimental-edge",
|
||||
};
|
||||
|
||||
const Admin = dynamic(
|
||||
() => import("bknd/ui").then((mod) => mod.Admin),
|
||||
{ ssr: false },
|
||||
);
|
||||
|
||||
export default function AdminPage() {
|
||||
return <Admin />;
|
||||
}
|
||||
```
|
||||
58
docs/integration/remix.mdx
Normal file
58
docs/integration/remix.mdx
Normal file
@@ -0,0 +1,58 @@
|
||||
---
|
||||
title: 'Remix'
|
||||
description: 'Run bknd inside Remix'
|
||||
---
|
||||
import InstallBknd from '/snippets/install-bknd.mdx';
|
||||
|
||||
<Note>
|
||||
Remix SSR support is currently limited.
|
||||
</Note>
|
||||
|
||||
## Installation
|
||||
Install bknd as a dependency:
|
||||
<InstallBknd />
|
||||
|
||||
## Serve the API
|
||||
Create a new api splat route file at `app/routes/api.$.ts`:
|
||||
``` tsx
|
||||
// app/routes/api.$.ts
|
||||
import { serve } from "bknd/adapter/remix";
|
||||
|
||||
const handler = serve({
|
||||
connection: {
|
||||
type: "libsql",
|
||||
config: {
|
||||
url: "http://localhost:8080"
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
export const loader = handler;
|
||||
export const action = handler;
|
||||
```
|
||||
|
||||
## Enabling the Admin UI
|
||||
Create a new splat route file at `app/routes/admin.$.tsx`:
|
||||
```tsx
|
||||
// app/routes/admin.$.tsx
|
||||
import { Suspense, lazy, useEffect, useState } from "react";
|
||||
import "bknd/dist/styles.css";
|
||||
|
||||
const Admin = lazy(() => import("bknd/ui")
|
||||
.then((mod) => ({ default: mod.Admin })));
|
||||
|
||||
export default function AdminPage() {
|
||||
const [loaded, setLoaded] = useState(false);
|
||||
useEffect(() => {
|
||||
setLoaded(true);
|
||||
}, []);
|
||||
if (!loaded) return null;
|
||||
|
||||
return (
|
||||
<Suspense>
|
||||
<Admin withProvider />
|
||||
</Suspense>
|
||||
);
|
||||
}
|
||||
|
||||
```
|
||||
Reference in New Issue
Block a user