mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 04:27:21 +00:00
feat: adding env aware endpoint to obtain sqlite connection, remove libsql hard dependency
This commit is contained in:
@@ -2,9 +2,16 @@ import path from "node:path";
|
||||
import { serve as honoServe } from "@hono/node-server";
|
||||
import { serveStatic } from "@hono/node-server/serve-static";
|
||||
import { registerLocalMediaAdapter } from "adapter/node/index";
|
||||
import { type RuntimeBkndConfig, createRuntimeApp, type RuntimeOptions } from "bknd/adapter";
|
||||
import {
|
||||
type RuntimeBkndConfig,
|
||||
createRuntimeApp,
|
||||
type RuntimeOptions,
|
||||
Connection,
|
||||
} from "bknd/adapter";
|
||||
import { config as $config } from "bknd/core";
|
||||
import { $console } from "core";
|
||||
import { sqlite } from "bknd/adapter/sqlite";
|
||||
import type { App } from "App";
|
||||
|
||||
type NodeEnv = NodeJS.ProcessEnv;
|
||||
export type NodeBkndConfig<Env = NodeEnv> = RuntimeBkndConfig<Env> & {
|
||||
@@ -28,10 +35,18 @@ export async function createApp<Env = NodeEnv>(
|
||||
console.warn("relativeDistPath is deprecated, please use distPath instead");
|
||||
}
|
||||
|
||||
let connection: Connection | undefined;
|
||||
if (Connection.isConnection(config.connection)) {
|
||||
connection = config.connection;
|
||||
} else {
|
||||
connection = sqlite(config.connection ?? { url: ":memory:" });
|
||||
}
|
||||
|
||||
registerLocalMediaAdapter();
|
||||
return await createRuntimeApp(
|
||||
{
|
||||
...config,
|
||||
connection,
|
||||
serveStatic: serveStatic({ root }),
|
||||
},
|
||||
// @ts-ignore
|
||||
@@ -45,8 +60,11 @@ export function createHandler<Env = NodeEnv>(
|
||||
args: Env = {} as Env,
|
||||
opts?: RuntimeOptions,
|
||||
) {
|
||||
let app: App | undefined;
|
||||
return async (req: Request) => {
|
||||
const app = await createApp(config, args ?? (process.env as Env), opts);
|
||||
if (!app) {
|
||||
app = await createApp(config, args ?? (process.env as Env), opts);
|
||||
}
|
||||
return app.fetch(req);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user