Kolaybase + Astro: A Backend for Content and Apps
Astro is great for fast content sites with islands of interactivity. Kolaybase adds the dynamic backend — PostgreSQL, auth, and storage — when you need it.
Install
npm install kolaybase-jsCreate the client
// src/lib/kolaybase.ts
import { createClient } from "kolaybase-js";
export const kb = createClient({
projectId: import.meta.env.PUBLIC_KOLAYBASE_PROJECT_ID,
apiKey: import.meta.env.PUBLIC_KOLAYBASE_ANON_KEY,
});Use PUBLIC_ env variables for the anon key. For server endpoints that need elevated access, use a service key from a non-public variable.
Fetch data in a page
---
// src/pages/posts.astro
import { kb } from "../lib/kolaybase";
const { data: posts } = await kb.from("posts").select("id, title");
---
<ul>{posts?.map((p) => <li>{p.title}</li>)}</ul>Fetch at build or request time
Use the SDK in frontmatter for SSG or SSR, depending on your Astro output mode.
Add a backend incrementally
Keep Astro's content speed and reach for Kolaybase only where you need dynamic data.
Auth and storage ready
kb.auth and kb.storage are available in server endpoints.
Frequently asked questions
- Does Kolaybase work with Astro SSR and SSG?
- Yes. Call the SDK in component frontmatter or endpoints. For SSG, data is fetched at build time; for SSR, on each request.
- Can I add interactive, authenticated islands?
- Yes. Use a framework island (React, Vue, Svelte) with the SDK and the anon key for authenticated, interactive components.
Other integrations
Build your Astro backend on Kolaybase
PostgreSQL, auth, storage, and a REST API — running in minutes.