Cloudflare Pages tRPC Route
Answered
Asiatic Lion posted this in #help-forum
Asiatic LionOP
I'm having an issue with trpc all the route returned 500.
i'm running 'nodejs' runtime on trpc route.
i'm running 'nodejs' runtime on trpc route.
from wrangler tail:
GET https://asdsad.m-.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, 4:49:34 pm
(warn) Routing failed. TypeError: adapterFn is not a function
(error) ⨯ Error: Dynamic require of "C:\asdsad\.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.
Answered by Asiatic Lion
prisma doesn't support edge runtime and cloudflare doesn't support nodejs runtime so i think im going to change to drizzle orm
https://www.reddit.com/r/nextjs/comments/1jornyu/how_to_properly_connect_a_nextjs_to_a_database/
https://www.reddit.com/r/nextjs/comments/1jornyu/how_to_properly_connect_a_nextjs_to_a_database/
2 Replies
Asiatic LionOP
//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 const runtime = 'nodejs';
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 }),
});
}
Asiatic LionOP
prisma doesn't support edge runtime and cloudflare doesn't support nodejs runtime so i think im going to change to drizzle orm
https://www.reddit.com/r/nextjs/comments/1jornyu/how_to_properly_connect_a_nextjs_to_a_database/
https://www.reddit.com/r/nextjs/comments/1jornyu/how_to_properly_connect_a_nextjs_to_a_database/
Answer