Integrate FrontendAdapters
Elysia Adapter
Serve QUESTPIE APIs with Elysia.
The Elysia adapter connects QUESTPIE to the Elysia framework, optimized for Bun.
Install
bun add @questpie/elysia elysiaServer Setup
Mount QUESTPIE as a catch-all route handler:
src/index.ts
import { Elysia } from "elysia"
import { createFetchHandler } from "@questpie/elysia/server"
import { app } from "#questpie"
const handler = createFetchHandler(app, { basePath: "/api" })
const server = new Elysia()
.all("/api/*", ({ request }) => handler(request))
.listen(3000)
console.log(`Running at ${server.server?.url}`)This mounts all QUESTPIE routes under /api/:
- Collections:
GET /api/collections/:name,POST /api/collections/:name, etc. - Globals:
GET /api/globals/:name,PUT /api/globals/:name - Auth:
POST /api/auth/* - Custom routes:
GET|POST /api/:routeName
Client Setup
Create a typed client for frontend use:
src/lib/client.ts
import { createClient } from "@questpie/elysia/client"
import type { AppConfig } from "#questpie"
export const client = createClient<AppConfig>({
baseURL: "http://localhost:3000/api",
})The client is fully typed — autocompletion for collections, fields, query operators, and custom routes.
Type Inference
The Elysia adapter provides end-to-end type safety:
// Typed collection queries
const posts = await client.collections.posts.find({
where: { status: { equals: "published" } },
orderBy: { createdAt: "desc" },
limit: 10,
})
// Typed custom routes
const stats = await client.routes.getDashboardStats.call({})CORS
Configure CORS using Elysia's built-in plugin:
import { cors } from "@elysiajs/cors"
const server = new Elysia()
.use(cors({ origin: "http://localhost:5173" }))
.all("/api/*", ({ request }) => handler(request))
.listen(3000)Related Pages
- Hono Adapter — Hono framework integration
- Next.js Adapter — Next.js App Router integration
- Type Inference — How type safety works end-to-end
- Querying — Query operators and pagination