oRPC Astro Adapter
Use oRPC inside an Astro project.
SKILL.mdskills/orpc-astro/SKILL.md
GitHubAstro Adapter
Astro is a JavaScript web framework optimized for fast, content-driven websites. For HTTP context, see the HTTP Adapter guide.
Basic
// pages/rpc/[...rest].ts
import { RPCHandler } from '@orpc/server/fetch'
import { onError } from '@orpc/server'
const handler = new RPCHandler(router, {
interceptors: [
onError((error) => {
console.error(error)
}),
],
})
export const prerender = false
export const ALL: APIRoute = async ({ request }) => {
const { response } = await handler.handle(request, {
prefix: '/rpc',
context: {},
})
return response ?? new Response('Not found', { status: 404 })
}
The
handlercan be any supported oRPC handler —RPCHandler,OpenAPIHandler, or a custom handler.