mirror of
https://github.com/bknd-io/bknd/
synced 2026-08-02 16:16:02 +00:00
32 lines
797 B
TypeScript
32 lines
797 B
TypeScript
import { type FrameworkBkndConfig, createFrameworkApp } from "adapter";
|
|
import { Api, type ApiOptions, type App } from "bknd";
|
|
|
|
export type AstroBkndConfig = FrameworkBkndConfig;
|
|
|
|
type TAstro = {
|
|
request: Request;
|
|
};
|
|
|
|
export type Options = {
|
|
mode?: "static" | "dynamic";
|
|
} & Omit<ApiOptions, "host"> & {
|
|
host?: string;
|
|
};
|
|
|
|
export function getApi(Astro: TAstro, options: Options = { mode: "static" }) {
|
|
return new Api({
|
|
host: new URL(Astro.request.url).origin,
|
|
headers: options.mode === "dynamic" ? Astro.request.headers : undefined
|
|
});
|
|
}
|
|
|
|
let app: App;
|
|
export function serve(config: AstroBkndConfig = {}) {
|
|
return async (args: TAstro) => {
|
|
if (!app) {
|
|
app = await createFrameworkApp(config);
|
|
}
|
|
return app.fetch(args.request);
|
|
};
|
|
}
|