small refactorings and cleanups, improved bun/node adapter, updated docs

This commit is contained in:
dswbx
2024-12-07 18:55:02 +01:00
parent 154703f873
commit 94cc4042d3
16 changed files with 224 additions and 203 deletions

View File

@@ -16,7 +16,8 @@ the admin panel.
// index.ts
import { serve } from "bknd/adapter/bun";
const handler = serve({
// if the configuration is omitted, it uses an in-memory database
serve({
connection: {
type: "libsql",
config: {
@@ -25,13 +26,6 @@ const handler = serve({
}
}
});
Bun.serve({
port: 1337,
fetch: handler
});
console.log("Server running at http://localhost:1337");
```
For more information about the connection object, refer to the [Setup](/setup) guide.

37
docs/integration/node.mdx Normal file
View File

@@ -0,0 +1,37 @@
---
title: 'Node'
description: 'Run bknd inside Node'
---
import InstallBknd from '/snippets/install-bknd.mdx';
## Installation
Install bknd as a dependency:
<InstallBknd />
## Serve the API & static files
The `serve` function of the Node adapter makes sure to also serve the static files required for
the admin panel.
``` tsx
// index.js
import { serve } from "bknd/adapter/node";
// if the configuration is omitted, it uses an in-memory database
/** @type {import("bknd/adapter/node").NodeAdapterOptions} */
const config = {
connection: {
type: "libsql",
config: {
url: ":memory:"
}
}
};
serve(config);
```
For more information about the connection object, refer to the [Setup](/setup) guide.
Run the application using node by executing:
```bash
node index.js
```