Elysia Adapter
Use oRPC inside an Elysia project by mounting a handler on a wildcard route.
Elysia is a high-performance web framework for Bun that adheres to the Fetch API, so oRPC integrates through the Fetch API Adapter.
Basic
import { onError } from '@orpc/server'
import { RPCHandler } from '@orpc/server/fetch'
import { Elysia } from 'elysia'
const handler = new RPCHandler(router, {
interceptors: [
onError((error) => {
console.error(error)
}),
],
})
const app = new Elysia()
.all('/rpc*', async ({ request }: { request: Request }) => {
const { response } = await handler.handle(request, {
prefix: '/rpc',
context: {} // Provide initial context if needed
})
return response ?? new Response('Not found', { status: 404 })
}, {
parse: 'none' // Skip Elysia's body parsing; oRPC reads the raw request itself
})
.listen(3000)
console.log('Elysia is running at http://localhost:3000')