mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 04:27:21 +00:00
unified runtime and framework adapters
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
import { Api, type ApiOptions, App, type CreateAppConfig } from "bknd";
|
||||
import { type FrameworkBkndConfig, createFrameworkApp } from "adapter";
|
||||
import { Api, type ApiOptions, type App } from "bknd";
|
||||
|
||||
export type AstroBkndConfig = FrameworkBkndConfig;
|
||||
|
||||
type TAstro = {
|
||||
request: Request;
|
||||
@@ -18,12 +21,10 @@ export function getApi(Astro: TAstro, options: Options = { mode: "static" }) {
|
||||
}
|
||||
|
||||
let app: App;
|
||||
export function serve(config: CreateAppConfig & { beforeBuild?: (app: App) => Promise<void> }) {
|
||||
export function serve(config: AstroBkndConfig = {}) {
|
||||
return async (args: TAstro) => {
|
||||
if (!app) {
|
||||
app = App.create(config);
|
||||
await config.beforeBuild?.(app);
|
||||
await app.build();
|
||||
app = await createFrameworkApp(config);
|
||||
}
|
||||
return app.fetch(args.request);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user