mirror of
https://github.com/bknd-io/bknd/
synced 2026-08-02 08:06:00 +00:00
dfae51c368
The 'api' mode is being renamed to 'headless' to better reflect its purpose: serving the API without the admin UI. This change aligns with the existing framework concept of a headless backend. The 'standalone' mode is renamed to 'admin' to indicate that it serves both the API and the admin UI.
61 lines
1.5 KiB
TypeScript
61 lines
1.5 KiB
TypeScript
import { em, entity, text, boolean } from "bknd";
|
|
import { registerLocalMediaAdapter } from "bknd/adapter/node";
|
|
import type { Config } from "bknd/adapter/universal";
|
|
|
|
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: "random_gibberish_please_change_this",
|
|
},
|
|
},
|
|
media: {
|
|
enabled: true,
|
|
adapter: local({
|
|
path: "./public/uploads",
|
|
}),
|
|
},
|
|
},
|
|
adminOptions: {
|
|
adminBasepath: "/admin",
|
|
assetsPath: "/admin/",
|
|
logoReturnPath: "../..",
|
|
},
|
|
} satisfies Config<"admin">;
|