Chen
Chen4mo ago

Is it possible to change the base path?

I have my trpc server on an endpoint: api.examples.com/trpc - this should be the root, and trpc handles anything subsequent. But querying this with a client, I get the error:
TRPCError: No procedure found on path "trpc/me.details"
TRPCError: No procedure found on path "trpc/me.details"
Is it possible to have the trpc server factor out the /trpc part of the path?
1 Reply
Chen
ChenOP3mo ago
I'm using the awsLambdaRequestHandler from @trpc/server/adapters/aws-lambda:
// functions/.../index.ts
export const handler = awsLambdaRequestHandler({
router: appRouter,
createContext: createTrpcContext,
});
// functions/.../index.ts
export const handler = awsLambdaRequestHandler({
router: appRouter,
createContext: createTrpcContext,
});
And SST:
// sst.config.ts
export const trpc = new sst.aws.Function("Api", {
handler: "packages/functions/src/api/index.handler",
runtime: "nodejs20.x",
memory: "128 MB",
link: [database, auth],
url: true,
});

export const apiRouter = new sst.aws.Router("ApiRouter", {
domain: {
name: "api." + domain,
dns: sst.cloudflare.dns(),
},
routes: {
"/trpc/*": trpc.url,
},
});
// sst.config.ts
export const trpc = new sst.aws.Function("Api", {
handler: "packages/functions/src/api/index.handler",
runtime: "nodejs20.x",
memory: "128 MB",
link: [database, auth],
url: true,
});

export const apiRouter = new sst.aws.Router("ApiRouter", {
domain: {
name: "api." + domain,
dns: sst.cloudflare.dns(),
},
routes: {
"/trpc/*": trpc.url,
},
});
For what it's worth, I've done this as a workaround:
// functions/.../index.ts
const trpcHandler = awsLambdaRequestHandler({
router: appRouter,
createContext: createTrpcContext,
});

export const handler: APIGatewayProxyHandlerV2 = async (event, context) => {
if (event.rawPath.startsWith("/trpc")) {
event.rawPath = event.rawPath.slice(5);
if (event.rawPath === "") {
event.rawPath = "/";
}
}

if (event.requestContext?.http?.path) {
event.requestContext.http.path = event.rawPath;
}

return trpcHandler(event, context);
};
// functions/.../index.ts
const trpcHandler = awsLambdaRequestHandler({
router: appRouter,
createContext: createTrpcContext,
});

export const handler: APIGatewayProxyHandlerV2 = async (event, context) => {
if (event.rawPath.startsWith("/trpc")) {
event.rawPath = event.rawPath.slice(5);
if (event.rawPath === "") {
event.rawPath = "/";
}
}

if (event.requestContext?.http?.path) {
event.requestContext.http.path = event.rawPath;
}

return trpcHandler(event, context);
};

Did you find this page helpful?