mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 04:27:21 +00:00
added fully working astro example
This commit is contained in:
1
examples/astro/src/env.d.ts
vendored
Normal file
1
examples/astro/src/env.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/// <reference path="../.astro/types.d.ts" />
|
||||
18
examples/astro/src/pages/admin/[...admin].astro
Normal file
18
examples/astro/src/pages/admin/[...admin].astro
Normal file
@@ -0,0 +1,18 @@
|
||||
---
|
||||
import { Api } from "bknd";
|
||||
import { Admin } from "bknd/ui";
|
||||
import "bknd/dist/styles.css";
|
||||
|
||||
export const prerender = false;
|
||||
const api = new Api({
|
||||
host: new URL(Astro.request.url).origin,
|
||||
headers: Astro.request.headers
|
||||
});
|
||||
const user = api.getUser();
|
||||
---
|
||||
|
||||
<html>
|
||||
<body>
|
||||
<Admin withProvider={{ user }} client:load />
|
||||
</body>
|
||||
</html>
|
||||
18
examples/astro/src/pages/api/[...api].ts
Normal file
18
examples/astro/src/pages/api/[...api].ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import type { APIRoute } from "astro";
|
||||
import { App } from "bknd";
|
||||
|
||||
export const prerender = false;
|
||||
|
||||
export const ALL: APIRoute = async ({ request }) => {
|
||||
const app = App.create({
|
||||
connection: {
|
||||
type: "libsql",
|
||||
config: {
|
||||
url: "http://127.0.0.1:8080"
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
await app.build();
|
||||
return app.fetch(request);
|
||||
};
|
||||
16
examples/astro/src/pages/index.astro
Normal file
16
examples/astro/src/pages/index.astro
Normal file
@@ -0,0 +1,16 @@
|
||||
---
|
||||
import { Api } from "bknd";
|
||||
const api = new Api({
|
||||
host: new URL(Astro.request.url).origin
|
||||
});
|
||||
const { data } = await api.data.readMany("todos");
|
||||
---
|
||||
|
||||
|
||||
<h1>Home (static)</h1>
|
||||
<h2>Data</h2>
|
||||
<pre>{JSON.stringify(data, null, 2)}</pre>
|
||||
|
||||
<a href="/admin">Admin</a> -
|
||||
<a href="/ssr">SSR (with auth)</a> -
|
||||
<a href="/">Home (static)</a>
|
||||
23
examples/astro/src/pages/ssr.astro
Normal file
23
examples/astro/src/pages/ssr.astro
Normal file
@@ -0,0 +1,23 @@
|
||||
---
|
||||
import { Api } from "bknd";
|
||||
const api = new Api({
|
||||
host: new URL(Astro.request.url).origin,
|
||||
headers: Astro.request.headers
|
||||
});
|
||||
const { data } = await api.data.readMany("todos");
|
||||
const user = api.getUser();
|
||||
console.log("user", user);
|
||||
|
||||
export const prerender = false;
|
||||
---
|
||||
|
||||
<h1>SSR</h1>
|
||||
<h2>Data</h1>
|
||||
<pre>{JSON.stringify(data, null, 2)}</pre>
|
||||
|
||||
<h2>User</h1>
|
||||
<pre>{JSON.stringify(user, null, 2)}</pre>
|
||||
|
||||
<a href="/admin">Admin</a> -
|
||||
<a href="/ssr">SSR (with auth)</a> -
|
||||
<a href="/">Home (static)</a>
|
||||
Reference in New Issue
Block a user