mirror of
https://github.com/shishantbiswas/bknd-examples.git
synced 2026-02-27 12:01:16 +00:00
refactor: using adapter primitives in place of nextjs adapter
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
"scripts": {
|
||||
"dev": "vite dev --port 3000",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview",
|
||||
"start": "vite preview",
|
||||
"test": "vitest run"
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
17
src/bknd.ts
17
src/bknd.ts
@@ -1,7 +1,15 @@
|
||||
// Both work just fine
|
||||
// import { getApp as getBkndApp } from "bknd/adapter/react-router";
|
||||
import { getApp as getBkndApp } from "bknd/adapter/nextjs";
|
||||
// import { getApp as getBkndApp } from "bknd/adapter/nextjs";
|
||||
import config from "../bknd.config";
|
||||
import { BkndConfig, createFrameworkApp } from "bknd/adapter";
|
||||
|
||||
// --------------------------------- TANSTACK ADAPTER PROTOTYPE -----------------------------------
|
||||
export async function getApp<Env = NodeJS.ProcessEnv>(
|
||||
config: BkndConfig<Env>,
|
||||
args: Env = process.env as Env,
|
||||
) {
|
||||
return await createFrameworkApp(config, args);
|
||||
}
|
||||
// --------------------------------- TANSTACK ADAPTER PROTOTYPE -----------------------------------
|
||||
|
||||
export async function getApi({
|
||||
headers,
|
||||
@@ -10,7 +18,8 @@ export async function getApi({
|
||||
verify?: boolean;
|
||||
headers?: Headers;
|
||||
}) {
|
||||
const app = await getBkndApp(config, process.env);
|
||||
const app = await getApp(config, process.env);
|
||||
// const app = await getBkndApp(config, process.env);
|
||||
|
||||
if (verify) {
|
||||
const api = app.getApi({ headers });
|
||||
|
||||
@@ -37,7 +37,7 @@ function RootDocument({ children }: { children: React.ReactNode }) {
|
||||
<HeadContent />
|
||||
</head>
|
||||
<body>
|
||||
<ClientProvider verbose baseUrl="http://localhost:3000">
|
||||
<ClientProvider verbose baseUrl={import.meta.env.APP_URL}>
|
||||
{children}
|
||||
</ClientProvider>
|
||||
<TanStackDevtools
|
||||
|
||||
@@ -3,7 +3,6 @@ import { useAuth } from "bknd/client";
|
||||
import "bknd/dist/styles.css";
|
||||
import { Admin } from "bknd/ui";
|
||||
|
||||
|
||||
export const Route = createFileRoute("/admin/$")({
|
||||
ssr: false,
|
||||
component: RouteComponent,
|
||||
@@ -18,7 +17,7 @@ function RouteComponent() {
|
||||
basepath: "/admin",
|
||||
logo_return_path: "/../",
|
||||
}}
|
||||
baseUrl="http://localhost:3000"
|
||||
baseUrl={import.meta.env.APP_URL}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,31 @@
|
||||
import { createFileRoute } from "@tanstack/react-router";
|
||||
import config from "../../bknd.config";
|
||||
import { BkndConfig, createFrameworkApp } from "bknd/adapter";
|
||||
|
||||
// Works fine
|
||||
import { serve } from "bknd/adapter/nextjs";
|
||||
// import { getApp } from "bknd/adapter/nextjs";
|
||||
// const handler = serve({
|
||||
// ...config,
|
||||
// });
|
||||
|
||||
const handler = serve({
|
||||
...config,
|
||||
});
|
||||
// --------------------------------- TANSTACK ADAPTER PROTOTYPE -----------------------------------
|
||||
|
||||
export async function getApp<Env = NodeJS.ProcessEnv>(
|
||||
config: BkndConfig<Env>,
|
||||
args: Env = process.env as Env,
|
||||
) {
|
||||
return await createFrameworkApp(config, args);
|
||||
}
|
||||
|
||||
function serve(config: BkndConfig) {
|
||||
return async (request: Request) => {
|
||||
const app = await getApp(config, process.env);
|
||||
return app.fetch(request);
|
||||
};
|
||||
}
|
||||
|
||||
const handler = serve(config);
|
||||
|
||||
// --------------------------------- TANSTACK ADAPTER PROTOTYPE -----------------------------------
|
||||
|
||||
export const Route = createFileRoute("/api/$")({
|
||||
server: {
|
||||
|
||||
Reference in New Issue
Block a user