Elysia Adapter
Elysia is a high-performance web framework for Bun that adheres to the Fetch API. For additional context, refer to the HTTP Adapter guide.
Basic
ts
import { Elysia } from 'elysia'
import { RPCHandler } from '@orpc/server/fetch'
import { onError } from '@orpc/server'
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',
})
return response ?? new Response('Not Found', { status: 404 })
}, {
parse: 'none' // Disable Elysia body parser to prevent "body already used" error
})
.listen(3000)
console.log(
`🦊 Elysia is running at http://localhost:3000`
)INFO
The handler can be any supported oRPC handler, such as RPCHandler, OpenAPIHandler, or another custom handler.
