mirror of
https://github.com/bknd-io/bknd.git
synced 2026-10-23 14:55:11 +00:00
added minimal astro adapter + improved the example
This commit is contained in:
1 parent
6eb0d2242f
commit
582dbd4272
11 files changed
+301
-35
No files matched your search
@@ -0,0 +1,21 @@
|
||||
import { Api, type ApiOptions } from "bknd";
|
||||
|
||||
type TAstro = {
|
||||
request: {
|
||||
url: string;
|
||||
headers: Headers;
|
||||
};
|
||||
};
|
||||
|
||||
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
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user