@@ -102,7 +101,7 @@ function App() {
-// Account
-// {user ? ( -//
diff --git a/.gitignore b/.gitignore index 2040117..9bf2b62 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,5 @@ count.txt .output .vinxi todos.json -public/uploads \ No newline at end of file +public/uploads +data \ No newline at end of file diff --git a/README.md b/README.md index 2427e4c..ad0386f 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,33 @@ bun run dev 3. **`src/routes/index.tsx`** - Using `getApp()` to fetch data in loader 3. **`src/routes/ssr.tsx`** - Server Side example with `getApp()` to fetch data on server +## Directory Structure + +```txt +├── bknd.config.ts +├── bun.lock +├── docker-compose.yml +├── Dockerfile +├── package.json +├── public +├── README.md +├── src +│ ├── bknd.ts # bknd singleton initialization +│ ├── logo.svg +│ ├── router.tsx +│ ├── routes +│ │ ├── api.$.ts # bknd API handler +│ │ ├── admin.$.tsx # Admin Dashboard +│ │ ├── index.tsx # Client Side Rendering example +│ │ └── ssr.tsx # Server Side Rendering example +│ │ ├── __root.tsx +│ ├── routeTree.gen.ts +│ └── styles.css +├── tsconfig.json +└── vite.config.ts +``` + + ## API Endpoints - `GET /admin` - for Admin Dashboard diff --git a/bknd.config.ts b/bknd.config.ts index a9a148f..7955526 100644 --- a/bknd.config.ts +++ b/bknd.config.ts @@ -1,4 +1,4 @@ -import { em, entity, text, boolean, libsql } from "bknd"; +import { em, entity, text, boolean, libsql, type Connection } from "bknd"; import type { TanstackStartConfig } from "bknd/adapter/tanstack-start"; import { registerLocalMediaAdapter } from "bknd/adapter/node"; @@ -19,10 +19,17 @@ declare module "bknd" { interface DB extends Database { } } +function getDBConnection(): Connection | { url: ":memory:" | (string & {}) } { + if (process.env.NODE_ENV !== "production") return { url: ":memory:" }; + + return libsql({ + url: process.env.DATABASE_URL, + }) +} + + export default { - connection: libsql({ - url: process.env.DATABASE_URL || "http://localhost:8080", - }), + connection: getDBConnection(), options: { // the seed option is only executed if the database was empty seed: async (ctx) => { diff --git a/docker-compose.yml b/docker-compose.yml index d7fcc89..49d9cbd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,8 +1,6 @@ services: app: - build: - context: . - dockerfile: Dockerfile + image: gitea.bsws.in/shishantbiswas/bknd-examples:tanstack-start deploy: resources: limits: diff --git a/src/bknd.ts b/src/lib/bknd.ts similarity index 93% rename from src/bknd.ts rename to src/lib/bknd.ts index 1f4ce97..5459c9f 100644 --- a/src/bknd.ts +++ b/src/lib/bknd.ts @@ -1,5 +1,5 @@ import { App } from "bknd"; -import config from "../bknd.config"; +import config from "../../bknd.config"; import { getApp as getBkndApp } from "bknd/adapter/tanstack-start"; declare global { diff --git a/src/routes/index.tsx b/src/routes/index.tsx index 5610c66..679c07e 100644 --- a/src/routes/index.tsx +++ b/src/routes/index.tsx @@ -4,7 +4,7 @@ import { useRouter, useRouterState, } from "@tanstack/react-router"; -import { getApi } from "@/bknd"; +import { getApi } from "@/lib/bknd"; import { createServerFn, useServerFn } from "@tanstack/react-start"; export const completeTodo = createServerFn({ method: "POST" }) @@ -57,7 +57,6 @@ export const getTodo = createServerFn({ method: "POST" }).handler(async () => { }); export const Route = createFileRoute("/")({ - ssr:false, component: App, loader: async () => { return await getTodo(); @@ -73,11 +72,11 @@ function App() { const addTodo = useServerFn(createTodo); return ( -
@@ -102,7 +101,7 @@ function App() {
-//