Compare commits

...

18 Commits

Author SHA1 Message Date
Cameron Pak b070fb591e fix(tests): resolve prepublishOnly failures in AppAuth and postgres tests 2026-04-03 08:30:47 -05:00
dswbx 81bf41ce34 Merge pull request #379 from jonaspm/chore/fix-manifestpath-warning
chore: Use dynamic import for manifest with Vite ignore. Fixes warning
2026-03-28 11:28:11 +01:00
dswbx d9ab583a16 Merge pull request #378 from jonaspm/chore/replace-deprecated-OptionsObjects
Replace deprecated OptionsObject with SpawnOptions and fix warning
2026-03-28 11:27:16 +01:00
dswbx e68df5e606 Merge pull request #377 from jonaspm/chore/dayjs-v1.11.20
chore: Bump dayjs to 1.11.20
2026-03-28 11:26:38 +01:00
dswbx 6304ef81f6 Merge pull request #373 from jonaspm/fix/example-sqlite-paths
fix: update local database URL to remove 'file:' prefix in examples
2026-03-28 11:24:07 +01:00
dswbx 6c7e82781d Merge pull request #362 from shishantbiswas/feature-nuxt-adapter
feat: Nuxt adapter
2026-03-28 10:55:14 +01:00
dswbx a8e5c45a22 bump 0.21.0-rc.1 2026-03-28 10:50:14 +01:00
dswbx ee28c2ef0c Merge pull request #372 from jonaspm/fix/broader-bearer-token-resolution
fix: Match Bearer case-insensitively and trim whitespace(s)
2026-03-28 10:35:43 +01:00
dswbx 9219bf3b3c test(auth, api): ensure bearer token is case-insensitive 2026-03-28 10:33:24 +01:00
Jonas Perusquia Morales e437ce7120 chore: Use dynamic import for manifest with Vite ignore. Fixes warning 2026-03-28 03:02:08 -06:00
Jonas Perusquia Morales 2417833ed7 chore: Replace Bun's deprecated OptionsObject with SpawnOptions and
remove stdout cast. Fix warning.
2026-03-28 02:56:26 -06:00
Jonas Perusquia Morales ab1eddcb6a chore: Bump dayjs to 1.11.20 2026-03-27 14:49:16 -06:00
Jonas Perusquia Morales dc8aca6a97 fix: update database URL to remove 'file:' prefix in examples 2026-03-24 13:30:54 -06:00
Jonas Perusquia Morales 4121597fa2 fix: Match Bearer case-insensitively and trim whitespace(s) 2026-03-24 12:20:17 -06:00
dswbx 9628720f87 test(AppReduced): remove redundant admin_base_path 2026-03-17 16:31:58 -05:00
dswbx ff216ec4e5 chore: remove unused admin_basepath and bump version to 0.21.0-rc.0 2026-03-17 16:31:58 -05:00
shishantbiswas 06f9c3ee15 refactor(docs): note for NuxtLink usage, added geist font in example, minor cleanups 2026-03-14 22:57:05 +05:30
shishantbiswas 7751ee5db8 init: nuxt adapter 2026-03-14 19:27:31 +05:30
47 changed files with 1073 additions and 22 deletions
+6
View File
@@ -70,4 +70,10 @@ describe("Api", async () => {
expect(params.token_transport).toBe("header"); expect(params.token_transport).toBe("header");
expect(params.host).toBe("http://another.com"); expect(params.host).toBe("http://another.com");
}); });
it("should extract tokens case insensitive", async () => {
const token = await sign({ sub: "test" }, "1234");
expect(new Api({ headers: new Headers({ Authorization: `Bearer ${token}` }) }).getAuthState().token).toBe(token);
expect(new Api({ headers: new Headers({ Authorization: `bearer ${token}` }) }).getAuthState().token).toBe(token);
})
}); });
+23
View File
@@ -38,4 +38,27 @@ describe("Authenticator", async () => {
expect(cookie).toStartWith("auth="); expect(cookie).toStartWith("auth=");
expect(cookie).toEndWith("HttpOnly; Secure; SameSite=Strict"); expect(cookie).toEndWith("HttpOnly; Secure; SameSite=Strict");
}); });
test("bearer token is case insensitive", async () => {
const auth = new Authenticator({}, null as any, {
jwt: {
secret: "secret",
fields: ["sub"],
},
cookie: {
sameSite: "strict",
},
});
const token = await auth.jwt({ sub: "test" });
const res = await auth.resolveAuthFromRequest(new Headers({
Authorization: `Bearer ${token}`,
}));
expect((res as any).sub).toBe("test")
const res2 = await auth.resolveAuthFromRequest(new Headers({
Authorization: `bearer ${token}`,
}));
expect((res2 as any).sub).toBe("test")
})
}); });
+2 -2
View File
@@ -41,12 +41,12 @@ describe("postgres", () => {
beforeAll(async () => { beforeAll(async () => {
if (!(await isPostgresRunning())) { if (!(await isPostgresRunning())) {
await $`docker run --rm --name bknd-test-postgres -d -e POSTGRES_PASSWORD=${credentials.password} -e POSTGRES_USER=${credentials.user} -e POSTGRES_DB=${credentials.database} -p ${credentials.port}:5432 postgres:17`; await $`docker run --rm --name bknd-test-postgres -d -e POSTGRES_PASSWORD=${credentials.password} -e POSTGRES_USER=${credentials.user} -e POSTGRES_DB=${credentials.database} -p ${credentials.port}:5432 postgres:17`;
await $waitUntil("Postgres is running", isPostgresRunning); await $waitUntil("Postgres is running", isPostgresRunning, 500, 20);
await new Promise((resolve) => setTimeout(resolve, 500)); await new Promise((resolve) => setTimeout(resolve, 500));
} }
disableConsoleLog(); disableConsoleLog();
}); }, 30000);
afterAll(async () => { afterAll(async () => {
if (await isPostgresRunning()) { if (await isPostgresRunning()) {
try { try {
+1 -1
View File
@@ -149,7 +149,7 @@ describe("AppAuth", () => {
}); });
await app.build(); await app.build();
app.registerAdminController(); app.registerAdminController({ forceDev: true });
const spy = spyOn(app.module.auth.authenticator, "requestCookieRefresh"); const spy = spyOn(app.module.auth.authenticator, "requestCookieRefresh");
// register custom route // register custom route
@@ -206,8 +206,7 @@ describe("AppReduced", () => {
describe("withBasePath - double slash fix (admin_basepath with trailing slash)", () => { describe("withBasePath - double slash fix (admin_basepath with trailing slash)", () => {
it("should not produce double slashes when admin_basepath has trailing slash", () => { it("should not produce double slashes when admin_basepath has trailing slash", () => {
const options: BkndAdminProps["config"] = { const options: BkndAdminProps["config"] = {
basepath: "/", basepath: "/admin",
admin_basepath: "/admin/",
logo_return_path: "/", logo_return_path: "/",
}; };
@@ -220,8 +219,7 @@ describe("AppReduced", () => {
it("should work correctly when admin_basepath has no trailing slash", () => { it("should work correctly when admin_basepath has no trailing slash", () => {
const options: BkndAdminProps["config"] = { const options: BkndAdminProps["config"] = {
basepath: "/", basepath: "/admin",
admin_basepath: "/admin",
logo_return_path: "/", logo_return_path: "/",
}; };
@@ -233,8 +231,7 @@ describe("AppReduced", () => {
it("should handle absolute paths with admin_basepath trailing slash", () => { it("should handle absolute paths with admin_basepath trailing slash", () => {
const options: BkndAdminProps["config"] = { const options: BkndAdminProps["config"] = {
basepath: "/", basepath: "/admin",
admin_basepath: "/admin/",
logo_return_path: "/", logo_return_path: "/",
}; };
@@ -247,8 +244,7 @@ describe("AppReduced", () => {
it("should handle settings path with admin_basepath trailing slash", () => { it("should handle settings path with admin_basepath trailing slash", () => {
const options: BkndAdminProps["config"] = { const options: BkndAdminProps["config"] = {
basepath: "/", basepath: "/admin",
admin_basepath: "/admin/",
logo_return_path: "/", logo_return_path: "/",
}; };
+5
View File
@@ -335,6 +335,11 @@ async function buildAdapters() {
platform: "node", platform: "node",
}), }),
tsup.build({
...baseConfig("nuxt"),
platform: "node",
}),
tsup.build({ tsup.build({
...baseConfig("node"), ...baseConfig("node"),
platform: "node", platform: "node",
+3 -2
View File
@@ -3,10 +3,11 @@ import path from "node:path";
import c from "picocolors"; import c from "picocolors";
const basePath = new URL(import.meta.resolve("../../")).pathname.slice(0, -1); const basePath = new URL(import.meta.resolve("../../")).pathname.slice(0, -1);
type RunOptions = Omit<Bun.SpawnOptions.SpawnOptions<"ignore", "pipe", "pipe">, "stdout" | "stderr">;
async function run( async function run(
cmd: string[] | string, cmd: string[] | string,
opts: Bun.SpawnOptions.OptionsObject & {}, opts: RunOptions,
onChunk: (chunk: string, resolve: (data: any) => void, reject: (err: Error) => void) => void, onChunk: (chunk: string, resolve: (data: any) => void, reject: (err: Error) => void) => void,
): Promise<{ proc: Bun.Subprocess; data: any }> { ): Promise<{ proc: Bun.Subprocess; data: any }> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@@ -17,7 +18,7 @@ async function run(
}); });
// Read from stdout // Read from stdout
const reader = (proc.stdout as ReadableStream).getReader(); const reader = proc.stdout.getReader();
const decoder = new TextDecoder(); const decoder = new TextDecoder();
// Function to read chunks // Function to read chunks
+3
View File
@@ -15,6 +15,9 @@ const configs = {
nextjs: { nextjs: {
base_path: "/admin", base_path: "/admin",
}, },
nuxt: {
base_path: "/admin",
},
astro: { astro: {
base_path: "/admin", base_path: "/admin",
}, },
+9 -2
View File
@@ -3,7 +3,7 @@
"type": "module", "type": "module",
"sideEffects": false, "sideEffects": false,
"bin": "./dist/cli/index.js", "bin": "./dist/cli/index.js",
"version": "0.20.0", "version": "0.21.0-rc.1",
"description": "Lightweight Firebase/Supabase alternative built to run anywhere — incl. Next.js, React Router, Astro, Cloudflare, Bun, Node, AWS Lambda & more.", "description": "Lightweight Firebase/Supabase alternative built to run anywhere — incl. Next.js, React Router, Astro, Cloudflare, Bun, Node, AWS Lambda & more.",
"homepage": "https://bknd.io", "homepage": "https://bknd.io",
"repository": { "repository": {
@@ -60,7 +60,7 @@
"@xyflow/react": "^12.9.2", "@xyflow/react": "^12.9.2",
"aws4fetch": "^1.0.20", "aws4fetch": "^1.0.20",
"bcryptjs": "^3.0.3", "bcryptjs": "^3.0.3",
"dayjs": "^1.11.19", "dayjs": "^1.11.20",
"fast-xml-parser": "^5.3.1", "fast-xml-parser": "^5.3.1",
"hono": "4.10.4", "hono": "4.10.4",
"json-schema-library": "10.0.0-rc7", "json-schema-library": "10.0.0-rc7",
@@ -233,6 +233,11 @@
"import": "./dist/adapter/nextjs/index.js", "import": "./dist/adapter/nextjs/index.js",
"require": "./dist/adapter/nextjs/index.js" "require": "./dist/adapter/nextjs/index.js"
}, },
"./adapter/nuxt": {
"types": "./dist/types/adapter/nuxt/index.d.ts",
"import": "./dist/adapter/nuxt/index.js",
"require": "./dist/adapter/nuxt/index.js"
},
"./adapter/react-router": { "./adapter/react-router": {
"types": "./dist/types/adapter/react-router/index.d.ts", "types": "./dist/types/adapter/react-router/index.d.ts",
"import": "./dist/adapter/react-router/index.js", "import": "./dist/adapter/react-router/index.js",
@@ -287,6 +292,7 @@
"adapter/cloudflare": ["./dist/types/adapter/cloudflare/index.d.ts"], "adapter/cloudflare": ["./dist/types/adapter/cloudflare/index.d.ts"],
"adapter/vite": ["./dist/types/adapter/vite/index.d.ts"], "adapter/vite": ["./dist/types/adapter/vite/index.d.ts"],
"adapter/nextjs": ["./dist/types/adapter/nextjs/index.d.ts"], "adapter/nextjs": ["./dist/types/adapter/nextjs/index.d.ts"],
"adapter/nuxt": ["./dist/types/adapter/nuxt/index.d.ts"],
"adapter/react-router": ["./dist/types/adapter/react-router/index.d.ts"], "adapter/react-router": ["./dist/types/adapter/react-router/index.d.ts"],
"adapter/bun": ["./dist/types/adapter/bun/index.d.ts"], "adapter/bun": ["./dist/types/adapter/bun/index.d.ts"],
"adapter/node": ["./dist/types/adapter/node/index.d.ts"], "adapter/node": ["./dist/types/adapter/node/index.d.ts"],
@@ -318,6 +324,7 @@
"serverless", "serverless",
"cloudflare", "cloudflare",
"nextjs", "nextjs",
"nuxt",
"remix", "remix",
"react-router", "react-router",
"astro", "astro",
+1 -1
View File
@@ -121,7 +121,7 @@ export class Api {
} }
// try authorization header // try authorization header
const headerToken = this.options.headers.get("authorization")?.replace("Bearer ", ""); const headerToken = this.options.headers.get("authorization")?.replace(/^Bearer\s+/i, "");
if (headerToken) { if (headerToken) {
this.token_transport = "header"; this.token_transport = "header";
this.updateToken(headerToken); this.updateToken(headerToken);
+1
View File
@@ -0,0 +1 @@
export * from "./nuxt.adapter";
+15
View File
@@ -0,0 +1,15 @@
import { afterAll, beforeAll, describe } from "bun:test";
import * as nuxt from "./nuxt.adapter";
import { disableConsoleLog, enableConsoleLog } from "core/utils";
import { adapterTestSuite } from "adapter/adapter-test-suite";
import { bunTestRunner } from "adapter/bun/test";
beforeAll(disableConsoleLog);
afterAll(enableConsoleLog);
describe("nuxt adapter", () => {
adapterTestSuite(bunTestRunner, {
makeApp: nuxt.getApp,
makeHandler: nuxt.serve,
});
});
+30
View File
@@ -0,0 +1,30 @@
import { createRuntimeApp, type RuntimeBkndConfig } from "bknd/adapter";
export type NuxtEnv = NodeJS.ProcessEnv;
export type NuxtBkndConfig<Env = NuxtEnv> = RuntimeBkndConfig<Env>;
/**
* Get bknd app instance
* @param config - bknd configuration
* @param args - environment variables
*/
export async function getApp<Env>(
config: NuxtBkndConfig<Env> = {} as NuxtBkndConfig<Env>,
args: Env,
) {
return await createRuntimeApp(config, args);
}
/**
* Create middleware handler for Nuxt
* @param config - bknd configuration
* @param args - environment variables
*/
export function serve<Env>(
config: NuxtBkndConfig<Env> = {} as NuxtBkndConfig<Env>,
args: Env,
) {
return async (request: Request) => {
return (await getApp(config, args)).fetch(request);
};
}
+1 -1
View File
@@ -430,7 +430,7 @@ export class Authenticator<
let token: string | undefined; let token: string | undefined;
if (headers.has("Authorization")) { if (headers.has("Authorization")) {
const bearerHeader = String(headers.get("Authorization")); const bearerHeader = String(headers.get("Authorization"));
token = bearerHeader.replace("Bearer ", ""); token = bearerHeader.replace(/^Bearer\s+/i, "");
} else { } else {
const context = is_context ? (c as Context) : ({ req: { raw: { headers } } } as Context); const context = is_context ? (c as Context) : ({ req: { raw: { headers } } } as Context);
token = await this.getAuthCookie(context); token = await this.getAuthCookie(context);
+2 -1
View File
@@ -210,8 +210,9 @@ export class AdminController extends Controller {
}, },
}).then((res) => res.json()); }).then((res) => res.json());
} else { } else {
const manifestPath = "bknd/dist/manifest.json";
// @ts-ignore // @ts-ignore
manifest = await import("bknd/dist/manifest.json", { manifest = await import(/* @vite-ignore */ manifestPath, {
with: { type: "json" }, with: { type: "json" },
}).then((res) => res.default); }).then((res) => res.default);
} }
+1 -1
View File
@@ -77,7 +77,7 @@ export class AppReduced {
withBasePath(path: string | string[], absolute = false): string { withBasePath(path: string | string[], absolute = false): string {
const paths = Array.isArray(path) ? path : [path]; const paths = Array.isArray(path) ? path : [path];
return [absolute ? "~" : null, this.options.basepath, this.options.admin_basepath, ...paths] return [absolute ? "~" : null, this.options.basepath, ...paths]
.filter(Boolean) .filter(Boolean)
.join("/") .join("/")
.replace(/\/+/g, "/") .replace(/\/+/g, "/")
@@ -5,6 +5,7 @@
"astro", "astro",
"sveltekit", "sveltekit",
"tanstack-start", "tanstack-start",
"vite" "vite",
"nuxt"
] ]
} }
@@ -0,0 +1,402 @@
---
title: "Nuxt"
description: "Run bknd inside Nuxt"
tags: ["documentation"]
---
## Installation
To get started with Nuxt and bknd, create a new Nuxt project by following the [official guide](https://nuxt.com/docs/4.x/getting-started/installation), and then install bknd as a dependency:
<Tabs groupId='package-manager' persist items={[ 'npm', 'pnpm', 'yarn', 'bun']}>
```bash tab="npm"
npm install bknd
```
```bash tab="pnpm"
pnpm install bknd
```
```bash tab="yarn"
yarn add bknd
```
```bash tab="bun"
bun add bknd
```
</Tabs>
## Configuration
<Callout type="warning">
When run with Node.js, a version of 22 (LTS) or higher is required. Please
verify your version by running `node -v`, and
[upgrade](https://nodejs.org/en/download/) if necessary.
</Callout>
Now create a `bknd.config.ts` file in the root of your project:
```typescript title="bknd.config.ts"
import type NuxtBkndConfig from "bknd/adapter/nuxt";
import { em, entity, text, boolean } from "bknd";
import { secureRandomString } from "bknd/utils";
const schema = em({
todos: entity("todos", {
title: text(),
done: boolean(),
}),
});
export default {
connection: {
url: "file:data.db",
},
config: {
data: schema.toJSON(),
auth: {
enabled: true,
jwt: {
secret: secureRandomString(32),
},
},
},
options: {
// the seed option is only executed if the database was empty
seed: async (ctx) => {
// create some entries
await ctx.em.mutator("todos").insertMany([
{ title: "Learn bknd", done: true },
{ title: "Build something cool", done: false },
]);
// and create a user
await ctx.app.module.auth.createUser({
email: "test@bknd.io",
password: "12345678",
});
},
},
} satisfies NuxtBkndConfig;
```
For more information about the connection object, refer to the [Database](/usage/database) guide.
See [bknd.config.ts](/extending/config) for more information on how to configure bknd. The `NuxtBkndConfig` type extends the base config type with the following properties:
```typescript
export type NuxtBkndConfig<Env = NuxtEnv> = FrameworkBkndConfig<Env>;
```
## Serve the API and Admin UI
The Nuxt adapter uses Nuxt middleware to handle API requests and serve the Admin UI. Create a `/server/middleware/bknd.ts` file:
```typescript title="/server/middleware/bknd.ts"
import { serve } from "bknd/adapter/nuxt";
import config from "../../bknd.config";
const handler = serve(config, process.env);
export default defineEventHandler(async (event) => {
const pathname = event.path;
const request = toWebRequest(event);
if (pathname.startsWith("/api") || pathname !== "/") {
const res = await handle(request);
if (res && res.status !== 404) {
return res;
}
}
});
```
<Callout type="success">
You can visit https://localhost:3000/admin to see the admin UI. Additionally you can create more todos as you explore the admin UI.
</Callout>
Create a helper file to instantiate the bknd instance and retrieve the API, importing the configuration from the `bknd.config.ts` file:
```ts title="server/utils/bknd.ts"
import { type NuxtBkndConfig, getApp as getNuxtApp } from "bknd/adapter/nuxt";
import bkndConfig from "../../bknd.config";
export async function getApp<Env = NodeJS.ProcessEnv>(
config: NuxtBkndConfig<Env>,
args: Env = process.env as Env,
) {
return await getNuxtApp(config, args);
}
export async function getApi({ headers, verify }: { verify?: boolean; headers?: Headers }) {
const app = await getApp(bkndConfig, process.env);
if (verify) {
const api = app.getApi({ headers });
await api.verifyAuth();
return api;
}
return app.getApi();
};
```
<Callout type="info">
The adapter uses `process.env` to access environment variables, this works because Nuxt uses Nitro underneath and it will use polyfills for `process.env` making it platform/runtime agnostic.
</Callout>
## Example usage of the API
You can use the `getApp` function to access the bknd API in your app to expose endpoints,
Here are some examples:
```typescript title="server/routes/todos.post.ts"
export default defineEventHandler(async (event) => {
const body = await readBody(event);
const { data, action } = body;
const api = await getApi({});
switch (action) {
case 'get': {
const limit = 5;
const todos = await api.data.readMany("todos", { limit, sort: "-id" });
return { total: todos.body.meta.total, todos, limit };
}
case 'create': {
return await api.data.createOne("todos", { title: data.title });
}
case 'delete': {
return await api.data.deleteOne("todos", data.id);
}
case 'toggle': {
return await api.data.updateOne("todos", data.id, { done: !data.done });
}
default: {
return { path: action };
}
}
});
```
<Callout type="warning">
This can't be done in the `server/api` directory as it will collide with the API endpoints created by the middleware. We will use [defineEventHandler](https://nuxt.com/docs/4.x/directory-structure/server) in the [server/routes](https://nuxt.com/docs/4.x/directory-structure/server) directory to create endpoints and use them in conjunction with composables to access the API safely.
</Callout>
### Using the API through composables
To use the API in your frontend components/pages, you can create a composable that uses the enpoints created in previous steps:
```typescript title="app/composables/useTodoActions.ts"
import type { DB } from "bknd";
type Todo = DB["todos"];
export const useTodoActions = () => {
const fetchTodos = () =>
$fetch<{ limit: number; todos: Array<Todo>; total: number }>("/todos", {
method: "POST",
body: { action: "get" },
});
const createTodo = (title: string) =>
$fetch("/todos", {
method: "POST",
body: { action: "create", data: { title } },
});
const deleteTodo = (todo: Todo) =>
$fetch("/todos", {
method: "POST",
body: { action: "delete", data: { id: todo.id } },
});
const toggleTodo = (todo: Todo) =>
$fetch("/todos", {
method: "POST",
body: { action: "toggle", data: todo },
});
return { fetchTodos, createTodo, deleteTodo, toggleTodo };
};
```
### Usage in a page/component
Make a composable to fetch the todos:
```ts title="app/composables/useTodoActions.ts"
import type { DB } from "bknd";
type Todo = DB["todos"];
export const useTodoActions = () => {
const fetchTodos = () =>
$fetch<{ limit: number; todos: Array<Todo>; total: number }>("/todos", {
method: "POST",
body: { action: "get" },
});
const createTodo = (title: string) =>
$fetch("/todos", {
method: "POST",
body: { action: "create", data: { title } },
});
const deleteTodo = (todo: Todo) =>
$fetch("/todos", {
method: "POST",
body: { action: "delete", data: { id: todo.id } },
});
const toggleTodo = (todo: Todo) =>
$fetch("/todos", {
method: "POST",
body: { action: "toggle", data: todo },
});
return { fetchTodos, createTodo, deleteTodo, toggleTodo };
};
```
Then use the `useTodoActions` composable in a page:
```vue title="app/pages/todos.vue"
<script lang="ts" setup>
const { fetchTodos, createTodo, deleteTodo, toggleTodo } = useTodoActions();
const { data:todos, execute } = await useAsyncData("todos", () => fetchTodos());
onMounted(() => {
execute();
});
</script>
<template>
<div
v-if="todos"
className="flex flex-col items-center justify-center min-h-screen p-8 pb-20 gap-16 sm:p-20"
>
<main className="flex flex-col gap-8 row-start-2 justify-center items-center sm:items-start">
<div class="flex flex-row items-center ">
<img class="dark:invert size-24" src="/nuxt.svg" alt="Nuxt logo" />
<div class="ml-3.5 mr-2 font-mono opacity-70">&amp;</div>
<img class="dark:invert" src="/bknd.svg" alt="bknd logo" width="183" height="59" />
</div>
<div v-if="data?.todos">
<ul>
<li v-for="todo in data.todos" :key="todo.id">
{{ todo.title }}
<button @click="toggleTodo(todo)">Toggle</button>
<button @click="deleteTodo(todo)">Delete</button>
</li>
</ul>
<form @submit.prevent="createTodo('New Todo')">
<input type="text" placeholder="New Todo" />
<button type="submit">Add</button>
</form>
</div>
<div v-else className="flex flex-col gap-1">
<p>
No todos found.
</p>
</div>
</main>
</div>
</template>
```
<Callout type="success">
You can visit https://localhost:3000/todos to see all the todos.
</Callout>
### Using authentication
Make a composable to fetch the user:
```ts title="app/composables/useUser.ts"
import type { User } from "bknd";
export const useUser = () => {
const getUser = () => $fetch("/api/auth/me") as Promise<{ user: User }>;
return { getUser };
};
```
Then use the `useUser` composable in a page:
```vue title="app/pages/user.vue"
<script lang="ts" setup>
const { getUser } = useUser();
const { data, status: userStatus, execute } = await useAsyncData("user", () => getUser());
onMounted(() => {
execute();
});
</script>
<template>
<div
v-if="userStatus !== 'pending'"
className="flex flex-col items-center justify-center min-h-screen p-8 pb-20 gap-16 sm:p-20"
>
<main className="flex flex-col gap-8 row-start-2 justify-center items-center sm:items-start">
<div class="flex flex-row items-center ">
<img class="dark:invert size-24" src="/nuxt.svg" alt="Nuxt logo" />
<div class="ml-3.5 mr-2 font-mono opacity-70">&amp;</div>
<img class="dark:invert" src="/bknd.svg" alt="bknd logo" width="183" height="59" />
</div>
<div v-if="data?.user">
Logged in as {{ data.user.email }}.
<a className="font-medium underline" href='/api/auth/logout'>
Logout
</a>
</div>
<div v-else className="flex flex-col gap-1">
<p>
Not logged in.
<a className="font-medium underline" href="/admin/auth/login">
Login
</a>
</p>
<p className="text-xs opacity-50">
Sign in with:
<b>
<code>test@bknd.io</code>
</b>
/
<b>
<code>12345678</code>
</b>
</p>
</div>
</main>
<Footer />
</div>
</template>
```
## Important Note
Use `external` attribute on Nuxt links, anytime you are traversing to an external route (like `/api/*` which are handled by bknd's middleware) to prevent vue router from intercepting the link.
```vue
<NuxtLink external href="/admin">
Admin
</NuxtLink>
```
<Callout type="error">
If you don't use the `external` attribute, vue router will intercept the link and try to navigate to it, which will fail and result in a 404 error.
</Callout>
Check the [Nuxt repository example](https://github.com/bknd-io/bknd/tree/main/examples/nuxt) for more implementation details.
@@ -39,6 +39,12 @@ bknd seamlessly integrates with popular frameworks, allowing you to use what you
href="/integration/tanstack-start" href="/integration/tanstack-start"
/> />
<Card
icon={<Icon icon="simple-icons:nuxt" className="text-fd-primary !size-6" />}
title="Nuxt"
href="/integration/nuxt"
/>
<Card title="Yours missing?" href="https://github.com/bknd-io/bknd/issues/new"> <Card title="Yours missing?" href="https://github.com/bknd-io/bknd/issues/new">
Create a new issue to request a guide for your framework. Create a new issue to request a guide for your framework.
</Card> </Card>
@@ -156,6 +156,12 @@ Pick your framework or runtime to get started.
href="/integration/tanstack-start" href="/integration/tanstack-start"
/> />
<Card
icon={<Icon icon="simple-icons:nuxt" className="text-fd-primary !size-6" />}
title="Nuxt"
href="/integration/nuxt"
/>
<Card <Card
icon={<Icon icon="tabler:lambda" className="text-fd-primary !size-6" />} icon={<Icon icon="tabler:lambda" className="text-fd-primary !size-6" />}
title="AWS Lambda" title="AWS Lambda"
+1 -1
View File
@@ -6,7 +6,7 @@ import { type BunBkndConfig, serve } from "bknd/adapter/bun";
// this is optional, if omitted, it uses an in-memory database // this is optional, if omitted, it uses an in-memory database
const config: BunBkndConfig = { const config: BunBkndConfig = {
connection: { connection: {
url: "file:data.db", url: "data.db",
}, },
config: { config: {
media: { media: {
+1 -1
View File
@@ -7,7 +7,7 @@ import { serve } from "bknd/adapter/node";
/** @type {import("bknd/adapter/node").NodeBkndConfig} */ /** @type {import("bknd/adapter/node").NodeBkndConfig} */
const config = { const config = {
connection: { connection: {
url: "file:data.db", url: "data.db",
}, },
config: { config: {
media: { media: {
+27
View File
@@ -0,0 +1,27 @@
# Nuxt dev/build outputs
.output
.data
.nuxt
.nitro
.cache
dist
# Node dependencies
node_modules
# Logs
logs
*.log
# Misc
.DS_Store
.fleet
.idea
# Local env files
.env
.env.*
!.env.example
public/admin
data.db
+64
View File
@@ -0,0 +1,64 @@
# bknd starter: Nuxt
A minimal example of a Nuxt project with bknd integration.
## Project Structure
Inside of your Nuxt project, you'll see the following folders and files:
```text
.
├── app
│ ├── assets
│ │ └── css
│ ├── components
│ │ ├── Buttons.vue
│ │ ├── Footer.vue
│ │ └── List.vue
│ ├── composables
│ │ ├── useTodoActions.ts
│ │ └── useUser.ts
│ └── pages
│ ├── index.vue
│ └── user.vue
├── bknd.config.ts
├── bun.lock
├── nuxt.config.ts
├── package.json
├── public
│ ├── admin # generated by bknd and contains the admin UI
│ ├── bknd.ico
│ ├── bknd.svg
│ ├── favicon.ico
│ ├── file.svg
│ ├── globe.svg
│ ├── nuxt.svg
│ ├── robots.txt
│ └── window.svg
├── README.md
├── server
│ ├── middleware
│ │ └── bknd.ts # intercepts api and admin ui requests
│ ├── routes
│ │ └── todos.post.ts
│ └── utils
│ └── bknd.ts # initializes bknd instance
└── tsconfig.json
```
Here is a quick overview about how to adjust the behavior of `bknd`:
* Initialization of the `bknd` config with helper functions are located at `src/server/utils/bknd.ts`
* Admin UI is rendered at `src/server/middleware/bknd.ts`
## Commands
All commands are run from the root of the project, from a terminal:
| Command | Action |
|:--------------------------|:-------------------------------------------------|
| `npm install` | Installs dependencies |
| `npm run dev` | Starts local dev server at `localhost:3000` |
| `npm run build` | Build your production site |
## Want to learn more?
Feel free to check [our documentation](https://docs.bknd.io/integration/nuxt) or jump into our [Discord server](https://discord.gg/952SFk8Tb8).
+33
View File
@@ -0,0 +1,33 @@
@import url("https://fonts.googleapis.com/css2?family=Geist+Mono:wght@100..900&display=swap");
.geist-mono-100 {
font-optical-sizing: auto;
font-weight: 100;
font-style: normal;
}
:root {
--background: #ffffff;
--foreground: #171717;
font-family: "Geist Mono", monospace;
}
@media (prefers-color-scheme: dark) {
:root {
--background: #0a0a0a;
--foreground: #ededed;
}
}
@theme {
--font-sans: var(--font-geist-sans);
--font-mono: var(--font-geist-mono);
--color-background: var(--background);
--color-foreground: var(--foreground);
}
body {
background-color: var(--background);
color: var(--foreground);
font-family: var(--font-geist-mono-100);
}
+13
View File
@@ -0,0 +1,13 @@
<template>
<div className="flex gap-4 items-center flex-col sm:flex-row">
<a className="rounded-full border border-solid border-transparent transition-colors flex items-center justify-center bg-foreground gap-2 text-white hover:bg-[#383838] dark:hover:bg-[#ccc] text-sm sm:text-base h-10 sm:h-12 px-4 sm:px-5"
href="https://bknd.io/" target="_blank" rel="noopener noreferrer">
<img className="grayscale" src="/bknd.ico" alt="bknd logomark" width={20} height={20} />
Go To Bknd.io
</a>
<a className="rounded-full border border-solid border-black/[.08] dark:border-white/[.145] transition-colors flex items-center justify-center hover:bg-[#f2f2f2] dark:hover:bg-[#1a1a1a] hover:border-transparent text-sm sm:text-base h-10 sm:h-12 px-4 sm:px-5 sm:min-w-44"
href="https://docs.bknd.io/integration/nextjs" target="_blank" rel="noopener noreferrer">
Read our docs
</a>
</div>
</template>
+29
View File
@@ -0,0 +1,29 @@
<script lang="ts" setup>
import { computed } from 'vue'
import { useRoute } from 'vue-router'
const route = useRoute()
const pathname = computed(() => route.path)
</script>
<template>
<footer class="row-start-3 flex gap-6 flex-wrap items-center justify-center">
<NuxtLink class="flex items-center gap-2 hover:underline hover:underline-offset-4"
:to="pathname === '/' ? '/user' : '/'">
<img aria-hidden src="/file.svg" alt="File icon" width="16" height="16" />
{{ pathname === '/' ? 'User' : 'Home' }}
</NuxtLink>
<!-- external is attribute required to hit the trigger middleware -->
<NuxtLink external class="flex items-center gap-2 hover:underline hover:underline-offset-4" href="/admin/data">
<img aria-hidden src="/window.svg" alt="Window icon" width="16" height="16" />
Admin
</NuxtLink>
<a class="flex items-center gap-2 hover:underline hover:underline-offset-4" href="https://bknd.io" target="_blank"
rel="noopener noreferrer">
<img aria-hidden src="/globe.svg" alt="Globe icon" width="16" height="16" />
Go to bknd.io
</a>
</footer>
</template>
+21
View File
@@ -0,0 +1,21 @@
<script lang="ts" setup>
const props = withDefaults(defineProps<{ items?: any[] }>(), { items: () => [] })
function isPrimitive(val: unknown): boolean {
const t = typeof val
return t === 'string' || t === 'number' || t === 'boolean'
}
</script>
<template>
<ol class="list-inside list-decimal text-sm text-center sm:text-left w-full text-center">
<li
v-for="(item, i) in props.items"
:key="i"
:class="{ 'mb-2': i < props.items.length - 1 }"
>
<span v-if="isPrimitive(item)">{{ item }}</span>
<component v-else :is="item" />
</li>
</ol>
</template>
@@ -0,0 +1,31 @@
import type { DB } from "bknd";
type Todo = DB["todos"];
export const useTodoActions = () => {
const fetchTodos = () =>
$fetch<{ limit: number; todos: Array<Todo>; total: number }>("/todos", {
method: "POST",
body: { action: "get" },
});
const createTodo = (title: string) =>
$fetch("/todos", {
method: "POST",
body: { action: "create", data: { title } },
});
const deleteTodo = (todo: Todo) =>
$fetch("/todos", {
method: "POST",
body: { action: "delete", data: { id: todo.id } },
});
const toggleTodo = (todo: Todo) =>
$fetch("/todos", {
method: "POST",
body: { action: "toggle", data: todo },
});
return { fetchTodos, createTodo, deleteTodo, toggleTodo };
};
+6
View File
@@ -0,0 +1,6 @@
import type { User } from "bknd";
export const useUser = () => {
const getUser = () => $fetch("/api/auth/me") as Promise<{ user: User }>;
return { getUser };
};
+70
View File
@@ -0,0 +1,70 @@
<script lang="ts" setup>
const { fetchTodos, toggleTodo, createTodo, deleteTodo } = useTodoActions();
const { data: todos, refresh } = await useAsyncData('todos', () => fetchTodos());
async function handleSubmit(event: Event) {
event.preventDefault();
const form = event.currentTarget as HTMLFormElement;
if (!form) return;
const formData = new FormData(form);
const title = formData.get("title");
await createTodo(title as string);
refresh();
};
</script>
<template>
<div v-if="todos !== undefined"
class="grid grid-rows-[20px_1fr_20px] items-center justify-items-center min-h-screen p-8 pb-20 gap-16 sm:p-20">
<main class="flex flex-col gap-8 row-start-2 items-center sm:items-start">
<div class="flex flex-row items-center justify-evenly min-w-full">
<img class="size-24" src="/nuxt.svg" alt="Nuxt logo" />
<div class="ml-3.5 mr-2 font-mono opacity-70">&amp;</div>
<img class="dark:invert" src="/bknd.svg" alt="bknd logo" width="183" height="59" />
</div>
<List :items="['Get started with a full backend.', 'Focus on what matters instead of repetition.']" />
<div class="flex flex-col border border-black/15 dark:border-white/15 w-full py-4 px-5 gap-2">
<h2 class="font-mono mb-1 opacity-70"><code>What's next?</code></h2>
<div class="flex flex-col w-full gap-2">
<div v-if="todos.total > todos.limit"
class="bg-foreground/10 flex justify-center p-1 text-xs rounded text-foreground/40">
{{ todos.total - todos.limit }} more todo(s) hidden
</div>
<div class="flex flex-col gap-3">
<div v-for="todo in todos.todos" :key="String(todo.id)" class="flex flex-row">
<div class="flex flex-row flex-grow items-center gap-3 ml-1">
<input
type="checkbox"
class="flex-shrink-0 cursor-pointer"
:checked="Boolean(todo.done)"
@change="() => { toggleTodo(todo); refresh() }" />
<div class="text-foreground/90 leading-none">{{ todo.title }}</div>
</div>
<button type="button" class="cursor-pointer grayscale transition-all hover:grayscale-0 text-xs"
@click="async () => { await deleteTodo(todo); refresh() }">
</button>
</div>
</div>
<form class="flex flex-row w-full gap-3 mt-2" :key="todos.todos.map(t => t.id).join()" @submit="handleSubmit">
<input
type="text"
name="title"
placeholder="New todo"
class="py-2 px-4 flex flex-grow rounded-sm bg-black/5 focus:bg-black/10 dark:bg-white/5 dark:focus:bg-white/10 transition-colors outline-none" />
<button type="submit" class="cursor-pointer">Add</button>
</form>
</div>
</div>
</main>
<Footer />
</div>
</template>
+55
View File
@@ -0,0 +1,55 @@
<script lang="ts" setup>
const { getUser } = useUser();
const { data, status: userStatus, execute } = await useAsyncData("user", () => getUser());
onMounted(() => {
execute();
});
</script>
<template>
<div
v-if="userStatus !== 'pending'"
className="flex flex-col items-center justify-center min-h-screen p-8 pb-20 gap-16 sm:p-20"
>
<main className="flex flex-col gap-8 row-start-2 justify-center items-center sm:items-start">
<div class="flex flex-row items-center justify-evenly min-w-full">
<img class="size-24" src="/nuxt.svg" alt="Nuxt logo" />
<div class="ml-3.5 mr-2 font-mono opacity-70">&amp;</div>
<img
class="dark:invert"
src="/bknd.svg"
alt="bknd logo"
width="183"
height="59"
/>
</div>
<div v-if="data?.user">
Logged in as {{ data.user.email }}.
<NuxtLink external className="font-medium underline" href='/api/auth/logout'>
Logout
</NuxtLink>
</div>
<div v-else className="flex flex-col gap-1">
<p>
Not logged in.
<NuxtLink external className="font-medium underline" href="/admin/auth/login">
Login
</NuxtLink>
</p>
<p className="text-xs opacity-50">
Sign in with:
<b>
<code>test@bknd.io</code>
</b>
/
<b>
<code>12345678</code>
</b>
</p>
</div>
</main>
<Footer />
</div>
</template>
+59
View File
@@ -0,0 +1,59 @@
import { em, entity, text, boolean, } from "bknd";
import { secureRandomString } from "bknd/utils";
import type { NuxtBkndConfig } from "bknd/adapter/nuxt";
import { registerLocalMediaAdapter } from "bknd/adapter/node";
const local = registerLocalMediaAdapter();
const schema = em({
todos: entity("todos", {
title: text(),
done: boolean(),
}),
});
// register your schema to get automatic type completion
type Database = (typeof schema)["DB"];
declare module "bknd" {
interface DB extends Database { }
}
export default {
connection: { url: "file:data.db" },
options: {
// the seed option is only executed if the database was empty
seed: async (ctx) => {
// create some entries
await ctx.em.mutator("todos").insertMany([
{ title: "Learn bknd", done: true },
{ title: "Build something cool", done: false },
]);
// and create a user
await ctx.app.module.auth.createUser({
email: "test@bknd.io",
password: "12345678",
});
},
},
config: {
data: schema.toJSON(),
auth: {
enabled: true,
jwt: {
secret: secureRandomString(32),
},
},
media: {
enabled: true,
adapter: local({
path: "./public/uploads",
}),
},
},
adminOptions: {
adminBasepath: "/admin",
assetsPath: "/admin/",
logoReturnPath: "../..",
},
} satisfies NuxtBkndConfig;
+12
View File
@@ -0,0 +1,12 @@
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
compatibilityDate: "2025-07-15",
devtools: { enabled: false },
modules: ["@nuxtjs/tailwindcss"],
app: {
head: {
title: "Nuxt 🤝 Bknd.io",
},
},
css: ["assets/css/main.css"],
});
+21
View File
@@ -0,0 +1,21 @@
{
"name": "nuxbknd",
"type": "module",
"private": true,
"scripts": {
"build": "nuxt build",
"dev": "nuxt dev",
"generate": "nuxt generate",
"preview": "nuxt preview",
"typegen": "bunx tsx node_modules/.bin/bknd types --outfile bknd-types.d.ts",
"postinstall": "nuxt prepare && bun run bknd copy-assets --out public/admin"
},
"dependencies": {
"@nuxtjs/tailwindcss": "6.14.0",
"@types/node": "^25.2.3",
"bknd": "file:../../app",
"nuxt": "^4.3.1",
"vue": "^3.5.28",
"vue-router": "^4.6.4"
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

+14
View File
@@ -0,0 +1,14 @@
<svg
width="578"
height="188"
viewBox="0 0 578 188"
fill="black"
xmlns="http://www.w3.org/2000/svg"
>
<path
fill-rule="evenodd"
clip-rule="evenodd"
d="M41.5 34C37.0817 34 33.5 37.5817 33.5 42V146C33.5 150.418 37.0817 154 41.5 154H158.5C162.918 154 166.5 150.418 166.5 146V42C166.5 37.5817 162.918 34 158.5 34H41.5ZM123.434 113.942C124.126 111.752 124.5 109.42 124.5 107C124.5 94.2975 114.203 84 101.5 84C99.1907 84 96.9608 84.3403 94.8579 84.9736L87.2208 65.1172C90.9181 63.4922 93.5 59.7976 93.5 55.5C93.5 49.701 88.799 45 83 45C77.201 45 72.5 49.701 72.5 55.5C72.5 61.299 77.201 66 83 66C83.4453 66 83.8841 65.9723 84.3148 65.9185L92.0483 86.0256C87.1368 88.2423 83.1434 92.1335 80.7957 96.9714L65.4253 91.1648C65.4746 90.7835 65.5 90.3947 65.5 90C65.5 85.0294 61.4706 81 56.5 81C51.5294 81 47.5 85.0294 47.5 90C47.5 94.9706 51.5294 99 56.5 99C60.0181 99 63.0648 96.9814 64.5449 94.0392L79.6655 99.7514C78.9094 102.03 78.5 104.467 78.5 107C78.5 110.387 79.2321 113.603 80.5466 116.498L69.0273 123.731C67.1012 121.449 64.2199 120 61 120C55.201 120 50.5 124.701 50.5 130.5C50.5 136.299 55.201 141 61 141C66.799 141 71.5 136.299 71.5 130.5C71.5 128.997 71.1844 127.569 70.6158 126.276L81.9667 119.149C86.0275 125.664 93.2574 130 101.5 130C110.722 130 118.677 124.572 122.343 116.737L132.747 120.899C132.585 121.573 132.5 122.276 132.5 123C132.5 127.971 136.529 132 141.5 132C146.471 132 150.5 127.971 150.5 123C150.5 118.029 146.471 114 141.5 114C138.32 114 135.525 115.649 133.925 118.139L123.434 113.942Z"
/>
<path d="M243.9 151.5C240.4 151.5 237 151 233.7 150C230.4 149 227.4 147.65 224.7 145.95C222 144.15 219.75 142.15 217.95 139.95C216.15 137.65 215 135.3 214.5 132.9L219.3 131.1L218.25 149.7H198.15V39H219.45V89.25L215.4 87.6C216 85.2 217.15 82.9 218.85 80.7C220.55 78.4 222.7 76.4 225.3 74.7C227.9 72.9 230.75 71.5 233.85 70.5C236.95 69.5 240.15 69 243.45 69C250.35 69 256.5 70.8 261.9 74.4C267.3 77.9 271.55 82.75 274.65 88.95C277.85 95.15 279.45 102.25 279.45 110.25C279.45 118.25 277.9 125.35 274.8 131.55C271.7 137.75 267.45 142.65 262.05 146.25C256.75 149.75 250.7 151.5 243.9 151.5ZM238.8 133.35C242.8 133.35 246.25 132.4 249.15 130.5C252.15 128.5 254.5 125.8 256.2 122.4C257.9 118.9 258.75 114.85 258.75 110.25C258.75 105.75 257.9 101.75 256.2 98.25C254.6 94.75 252.3 92.05 249.3 90.15C246.3 88.25 242.8 87.3 238.8 87.3C234.8 87.3 231.3 88.25 228.3 90.15C225.3 92.05 222.95 94.75 221.25 98.25C219.55 101.75 218.7 105.75 218.7 110.25C218.7 114.85 219.55 118.9 221.25 122.4C222.95 125.8 225.3 128.5 228.3 130.5C231.3 132.4 234.8 133.35 238.8 133.35ZM308.312 126.15L302.012 108.6L339.512 70.65H367.562L308.312 126.15ZM288.062 150V39H309.362V150H288.062ZM341.762 150L313.262 114.15L328.262 102.15L367.412 150H341.762ZM371.675 150V70.65H392.075L392.675 86.85L388.475 88.65C389.575 85.05 391.525 81.8 394.325 78.9C397.225 75.9 400.675 73.5 404.675 71.7C408.675 69.9 412.875 69 417.275 69C423.275 69 428.275 70.2 432.275 72.6C436.375 75 439.425 78.65 441.425 83.55C443.525 88.35 444.575 94.3 444.575 101.4V150H423.275V103.05C423.275 99.45 422.775 96.45 421.775 94.05C420.775 91.65 419.225 89.9 417.125 88.8C415.125 87.6 412.625 87.1 409.625 87.3C407.225 87.3 404.975 87.7 402.875 88.5C400.875 89.2 399.125 90.25 397.625 91.65C396.225 93.05 395.075 94.65 394.175 96.45C393.375 98.25 392.975 100.2 392.975 102.3V150H382.475C380.175 150 378.125 150 376.325 150C374.525 150 372.975 150 371.675 150ZM488.536 151.5C481.636 151.5 475.436 149.75 469.936 146.25C464.436 142.65 460.086 137.8 456.886 131.7C453.786 125.5 452.236 118.35 452.236 110.25C452.236 102.35 453.786 95.3 456.886 89.1C460.086 82.9 464.386 78 469.786 74.4C475.286 70.8 481.536 69 488.536 69C492.236 69 495.786 69.6 499.186 70.8C502.686 71.9 505.786 73.45 508.486 75.45C511.286 77.45 513.536 79.7 515.236 82.2C516.936 84.6 517.886 87.15 518.086 89.85L512.686 90.75V39H533.986V150H513.886L512.986 131.7L517.186 132.15C516.986 134.65 516.086 137.05 514.486 139.35C512.886 141.65 510.736 143.75 508.036 145.65C505.436 147.45 502.436 148.9 499.036 150C495.736 151 492.236 151.5 488.536 151.5ZM493.336 133.8C497.336 133.8 500.836 132.8 503.836 130.8C506.836 128.8 509.186 126.05 510.886 122.55C512.586 119.05 513.436 114.95 513.436 110.25C513.436 105.65 512.586 101.6 510.886 98.1C509.186 94.5 506.836 91.75 503.836 89.85C500.836 87.85 497.336 86.85 493.336 86.85C489.336 86.85 485.836 87.85 482.836 89.85C479.936 91.75 477.636 94.5 475.936 98.1C474.336 101.6 473.536 105.65 473.536 110.25C473.536 114.95 474.336 119.05 475.936 122.55C477.636 126.05 479.936 128.8 482.836 130.8C485.836 132.8 489.336 133.8 493.336 133.8Z" />
</svg>

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

+1
View File
@@ -0,0 +1 @@
<svg fill="none" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="M14.5 13.5V5.41a1 1 0 0 0-.3-.7L9.8.29A1 1 0 0 0 9.08 0H1.5v13.5A2.5 2.5 0 0 0 4 16h8a2.5 2.5 0 0 0 2.5-2.5m-1.5 0v-7H8v-5H3v12a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1M9.5 5V2.12L12.38 5zM5.13 5h-.62v1.25h2.12V5zm-.62 3h7.12v1.25H4.5zm.62 3h-.62v1.25h7.12V11z" clip-rule="evenodd" fill="#666" fill-rule="evenodd"/></svg>

After

Width:  |  Height:  |  Size: 391 B

+1
View File
@@ -0,0 +1 @@
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><g clip-path="url(#a)"><path fill-rule="evenodd" clip-rule="evenodd" d="M10.27 14.1a6.5 6.5 0 0 0 3.67-3.45q-1.24.21-2.7.34-.31 1.83-.97 3.1M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16m.48-1.52a7 7 0 0 1-.96 0H7.5a4 4 0 0 1-.84-1.32q-.38-.89-.63-2.08a40 40 0 0 0 3.92 0q-.25 1.2-.63 2.08a4 4 0 0 1-.84 1.31zm2.94-4.76q1.66-.15 2.95-.43a7 7 0 0 0 0-2.58q-1.3-.27-2.95-.43a18 18 0 0 1 0 3.44m-1.27-3.54a17 17 0 0 1 0 3.64 39 39 0 0 1-4.3 0 17 17 0 0 1 0-3.64 39 39 0 0 1 4.3 0m1.1-1.17q1.45.13 2.69.34a6.5 6.5 0 0 0-3.67-3.44q.65 1.26.98 3.1M8.48 1.5l.01.02q.41.37.84 1.31.38.89.63 2.08a40 40 0 0 0-3.92 0q.25-1.2.63-2.08a4 4 0 0 1 .85-1.32 7 7 0 0 1 .96 0m-2.75.4a6.5 6.5 0 0 0-3.67 3.44 29 29 0 0 1 2.7-.34q.31-1.83.97-3.1M4.58 6.28q-1.66.16-2.95.43a7 7 0 0 0 0 2.58q1.3.27 2.95.43a18 18 0 0 1 0-3.44m.17 4.71q-1.45-.12-2.69-.34a6.5 6.5 0 0 0 3.67 3.44q-.65-1.27-.98-3.1" fill="#666"/></g><defs><clipPath id="a"><path fill="#fff" d="M0 0h16v16H0z"/></clipPath></defs></svg>

After

Width:  |  Height:  |  Size: 1.0 KiB

+3
View File
@@ -0,0 +1,3 @@
<svg viewBox="0 0 900 900" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M504.908 750H839.476C850.103 750.001 860.542 747.229 869.745 741.963C878.948 736.696 886.589 729.121 891.9 719.999C897.211 710.876 900.005 700.529 900 689.997C899.995 679.465 897.193 669.12 891.873 660.002L667.187 274.289C661.876 265.169 654.237 257.595 645.036 252.329C635.835 247.064 625.398 244.291 614.773 244.291C604.149 244.291 593.711 247.064 584.511 252.329C575.31 257.595 567.67 265.169 562.36 274.289L504.908 372.979L392.581 179.993C387.266 170.874 379.623 163.301 370.42 158.036C361.216 152.772 350.777 150 340.151 150C329.525 150 319.086 152.772 309.883 158.036C300.679 163.301 293.036 170.874 287.721 179.993L8.12649 660.002C2.80743 669.12 0.00462935 679.465 5.72978e-06 689.997C-0.00461789 700.529 2.78909 710.876 8.10015 719.999C13.4112 729.121 21.0523 736.696 30.255 741.963C39.4576 747.229 49.8973 750.001 60.524 750H270.538C353.748 750 415.112 713.775 457.336 643.101L559.849 467.145L614.757 372.979L779.547 655.834H559.849L504.908 750ZM267.114 655.737L120.551 655.704L340.249 278.586L449.87 467.145L376.474 593.175C348.433 639.03 316.577 655.737 267.114 655.737Z" fill="#00DC82"/>
</svg>

After

Width:  |  Height:  |  Size: 1.2 KiB

+2
View File
@@ -0,0 +1,2 @@
User-Agent: *
Disallow:
+1
View File
@@ -0,0 +1 @@
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M1.5 2.5h13v10a1 1 0 0 1-1 1h-11a1 1 0 0 1-1-1zM0 1h16v11.5a2.5 2.5 0 0 1-2.5 2.5h-11A2.5 2.5 0 0 1 0 12.5zm3.75 4.5a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5M7 4.75a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0m1.75.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5" fill="#666"/></svg>

After

Width:  |  Height:  |  Size: 385 B

+15
View File
@@ -0,0 +1,15 @@
import { serve } from "bknd/adapter/nuxt";
import config from "../../bknd.config";
export default defineEventHandler(async (event) => {
const pathname = event.path
const request = toWebRequest(event);
if (pathname.startsWith("/api") || pathname !== "/") {
const res = await serve(config, process.env)(request);
if (res && res.status !== 404) {
return res;
}
}
});
+31
View File
@@ -0,0 +1,31 @@
export default defineEventHandler(async (event) => {
const body = await readBody(event);
const { data, action } = body;
const api = await getApi({});
switch (action) {
case 'get': {
const limit = 5;
const todos = await api.data.readMany("todos", { limit, sort: "-id" });
return { total: todos.body.meta.total, todos, limit };
}
case 'create': {
return await api.data.createOne("todos", { title: data.title });
}
case 'delete': {
return await api.data.deleteOne("todos", data.id);
}
case 'toggle': {
return await api.data.updateOne("todos", data.id, { done: !data.done });
}
default: {
return { path: action };
}
}
});
+21
View File
@@ -0,0 +1,21 @@
import { type NuxtBkndConfig, getApp as getNuxtApp } from "bknd/adapter/nuxt";
import bkndConfig from "../../bknd.config";
export async function getApp<Env = NodeJS.ProcessEnv>(
config: NuxtBkndConfig<Env>,
args: Env = process.env as Env,
) {
return await getNuxtApp(config, args);
}
export async function getApi({ headers, verify }: { verify?: boolean; headers?: Headers }) {
const app = await getApp(bkndConfig, process.env);
if (verify) {
const api = app.getApi({ headers });
await api.verifyAuth();
return api;
}
return app.getApi();
}
+18
View File
@@ -0,0 +1,18 @@
{
// https://nuxt.com/docs/guide/concepts/typescript
"files": [],
"references": [
{
"path": "./.nuxt/tsconfig.app.json"
},
{
"path": "./.nuxt/tsconfig.server.json"
},
{
"path": "./.nuxt/tsconfig.shared.json"
},
{
"path": "./.nuxt/tsconfig.node.json"
}
]
}