improved astro adapter (serving api) + added documentation

This commit is contained in:
dswbx
2024-12-01 08:58:08 +01:00
parent b55fdd7516
commit feeb13c053
9 changed files with 166 additions and 23 deletions

View File

@@ -1,10 +1,8 @@
import { Api, type ApiOptions } from "bknd";
import { App, type CreateAppConfig } from "bknd";
type TAstro = {
request: {
url: string;
headers: Headers;
};
request: Request;
};
export type Options = {
@@ -19,3 +17,15 @@ export function getApi(Astro: TAstro, options: Options = { mode: "static" }) {
headers: options.mode === "dynamic" ? Astro.request.headers : undefined
});
}
let app: App;
export function serve(config: CreateAppConfig) {
return async (args: TAstro) => {
if (!app) {
app = App.create(config);
await app.build();
}
return app.fetch(args.request);
};
}