ezra8679
ezra8679
TTCTheo's Typesafe Cult
Created by ezra8679 on 7/17/2023 in #questions
Lambdas and Edge functions in same tRPC Project?
Drizzle sorry for the late reply
11 replies
TTCTheo's Typesafe Cult
Created by ezra8679 on 7/17/2023 in #questions
Lambdas and Edge functions in same tRPC Project?
ooh ty 🙂
11 replies
TTCTheo's Typesafe Cult
Created by ezra8679 on 7/17/2023 in #questions
Lambdas and Edge functions in same tRPC Project?
Yeah i have two routers with two different urls. I use a splitLink to determine which url to pick. New to T3 so there prob is a better way to do this but this works.
export const api = createTRPCNext<AppRouter>({
config() {
return {
/**
* Transformer used for data de-serialization from the server.
*
* @see https://trpc.io/docs/data-transformers
*/
transformer: superjson,

/**
* Links used to determine request flow from client to server.
*
* @see https://trpc.io/docs/links
*/
links: [
loggerLink({
enabled: (opts) =>
process.env.NODE_ENV === "development" ||
(opts.direction === "down" && opts.result instanceof Error),
}),
splitLink({
condition(op) {
const isEdge = op.path.includes("edge") === true;
return isEdge;
},
true: httpBatchLink({
url: `${getBaseUrl()}/api/trpc/edge`,
headers: {
Authorization: authToken,
},
}),
false: httpBatchLink({
url: `${getBaseUrl()}/api/trpc/lambda`,
headers: {
Authorization: authToken,
},
}),
}),
],
};
},
/**
* Whether tRPC should await queries when server rendering pages.
*
* @see https://trpc.io/docs/nextjs#ssr-boolean-default-false
*/
ssr: false,
});
export const api = createTRPCNext<AppRouter>({
config() {
return {
/**
* Transformer used for data de-serialization from the server.
*
* @see https://trpc.io/docs/data-transformers
*/
transformer: superjson,

/**
* Links used to determine request flow from client to server.
*
* @see https://trpc.io/docs/links
*/
links: [
loggerLink({
enabled: (opts) =>
process.env.NODE_ENV === "development" ||
(opts.direction === "down" && opts.result instanceof Error),
}),
splitLink({
condition(op) {
const isEdge = op.path.includes("edge") === true;
return isEdge;
},
true: httpBatchLink({
url: `${getBaseUrl()}/api/trpc/edge`,
headers: {
Authorization: authToken,
},
}),
false: httpBatchLink({
url: `${getBaseUrl()}/api/trpc/lambda`,
headers: {
Authorization: authToken,
},
}),
}),
],
};
},
/**
* Whether tRPC should await queries when server rendering pages.
*
* @see https://trpc.io/docs/nextjs#ssr-boolean-default-false
*/
ssr: false,
});
11 replies
TTCTheo's Typesafe Cult
Created by ezra8679 on 7/17/2023 in #questions
Lambdas and Edge functions in same tRPC Project?
Yeah splitting the router is what I did. Not the worst thing in the world to do. Thanks for the answer 🙂
11 replies