keem
Cloudflare Page tRPC route
I successfully deploy on cloudflare page but however i can't access tRPC route. i'm getting error 500. are there proper setup for open-next for tRPC to work?
Connected to asdsad, waiting for logs...
GET https://asdsadsad.workers.dev/api/trpc/public.publicProduct.getProductCategories,public.publicProduct.getFeatured?batch=1&input=%7B%220%22%3A%7B%22json%22%3Anull%2C%22meta%22%3A%7B%22values%22%3A%5B%22undefined%22%5D%7D%7D%2C%221%22%3A%7B%22json%22%3A%7B%22limit%22%3A3%7D%7D%7D - Ok @ 03/04/2025, 8:53:12 pm
(warn) Routing failed. TypeError: adapterFn is not a function
(error) ⨯ Error: Dynamic require of "asdasd\.open-next\server-functions\default\.next\server\app\api\trpc\[trpc]\route-938d507d.js" is not supported
(error) Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
(error) ⨯ Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
Connected to asdsad, waiting for logs...
GET https://asdsadsad.workers.dev/api/trpc/public.publicProduct.getProductCategories,public.publicProduct.getFeatured?batch=1&input=%7B%220%22%3A%7B%22json%22%3Anull%2C%22meta%22%3A%7B%22values%22%3A%5B%22undefined%22%5D%7D%7D%2C%221%22%3A%7B%22json%22%3A%7B%22limit%22%3A3%7D%7D%7D - Ok @ 03/04/2025, 8:53:12 pm
(warn) Routing failed. TypeError: adapterFn is not a function
(error) ⨯ Error: Dynamic require of "asdasd\.open-next\server-functions\default\.next\server\app\api\trpc\[trpc]\route-938d507d.js" is not supported
(error) Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
(error) ⨯ Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
// api/trpc/[trpc]/route.ts
import { fetchRequestHandler } from '@trpc/server/adapters/fetch';
import { appRouter } from '@/trpc/server/api/routers';
import { createTRPCContext } from '@/trpc/server/api/trpc';
export async function GET(req: Request) {
return fetchRequestHandler({
endpoint: '/api/trpc',
req,
router: appRouter,
createContext: ({ req, resHeaders, info }) => createTRPCContext({ req, resHeaders, info }),
});
}
export async function POST(req: Request) {
return fetchRequestHandler({
endpoint: '/api/trpc',
req,
router: appRouter,
createContext: ({ req, resHeaders, info }) => createTRPCContext({ req, resHeaders, info }),
});
}
// api/trpc/[trpc]/route.ts
import { fetchRequestHandler } from '@trpc/server/adapters/fetch';
import { appRouter } from '@/trpc/server/api/routers';
import { createTRPCContext } from '@/trpc/server/api/trpc';
export async function GET(req: Request) {
return fetchRequestHandler({
endpoint: '/api/trpc',
req,
router: appRouter,
createContext: ({ req, resHeaders, info }) => createTRPCContext({ req, resHeaders, info }),
});
}
export async function POST(req: Request) {
return fetchRequestHandler({
endpoint: '/api/trpc',
req,
router: appRouter,
createContext: ({ req, resHeaders, info }) => createTRPCContext({ req, resHeaders, info }),
});
}
4 replies