Astro
Run bknd inside Astro
Installation
Install bknd as a dependency:
For the Astro integration to work, you also need to add the react integration:
You also need to make sure to set the output to hybrid
in your Astro config:
If you don’t want to use React with Astro, there is also an option to serve the bknd Admin UI statically using Astro’s middleware. In case you’re interested in this, feel free to reach out in Discord or open an issue on GitHub.
Serve the API
Create a new catch-all route at src/pages/api/[...api].ts
:
For more information about the connection object, refer to the Setup guide. In the special case of astro, you may also use your Astro DB credentials since it’s also using LibSQL under the hood. Refer to the Astro DB documentation for more information.
Enabling the Admin UI
Create a new catch-all route at src/pages/admin/[...admin].astro
:
Example usage of the API
You use the API in both static and SSR pages. Just note that on static pages, authentication might not work as expected, because Cookies are not available in the static context.
Here is an example of using the API in static context:
On SSR pages, you can also access the authenticated user:
Check the astro repository example for more implementation details or a fully working example using Astro DB.