trpc-bun-adapter icon indicating copy to clipboard operation
trpc-bun-adapter copied to clipboard

Please share an example of code

Open ram0973 opened this issue 10 months ago • 0 comments

Hello sir, could you please explain, how to use this library?

I wrote this code, and it's working:

import index from "./index.html";
import { fetchRequestHandler } from "@trpc/server/adapters/fetch";
Bun.serve({
  routes: {
    "/trpc/*": async (req) => {
       return fetchRequestHandler({
       createContext: () => ({}) as never,
        req: req,
        endpoint: '/trpc',
        router: router
      })
    },
    "/*": index,
  },
})

Now how to use this library?

const indexHandler = createBunHttpHandler({
    router,
    // optional arguments:
    endpoint: '/trpc',
    onError: console.error,
    batching: {
        enabled: true,
    },
    emitWsUpgrades: false, // pass true to upgrade to WebSocket
});

routes: {
    "/trpc/*": () => indexHandler ??????

ram0973 avatar May 29 '25 05:05 ram0973