T
tRPC

charset=utf8 results in empty input

charset=utf8 results in empty input

Mmrjack9/4/2023
I'm using trpc-openapi and some of our customers are using Zapier to communicate with it. Zapier uses the header Content-Type: application/json; charset=utf-8 - note the additional charset=utf-8 When charset=utf-8 exists, the input to the relevant procedure is {} Has anybody encountered this? Is there a way to support it?
Mmrjack9/4/2023
Note I'm using adapters/aws-lambda
Ssachin9/6/2023
i think i know why this is happening
Mmrjack9/6/2023
@sachinraja - a penny for your thoughts? I found a few string comparisons to "application/json" in the codebase - I thought that might be it
Ssachin9/6/2023
yeah ill do a PR - should probably be doing .includes instead sorry i meant to follow up on this lol
Mmrjack9/6/2023
Thanks @sachinraja ❤️
Ssachin9/6/2023
can i ask you to try something with a patch (patch-package)?
Mmrjack9/6/2023
I'm just in a meeting right now - I'd be happy to give it a crack in about 1h
Ssachin9/6/2023
awesome 👍
Mmrjack9/6/2023
n.b. I'm on Yarn 3 which has it's own patch package system. I can just do a patch manually though if need be
Ssachin9/6/2023
ok cool ill see if i can do a canary publish actually I thought I knew why this was happening but now I do not. I just read that you're using the aws lambda adapter so that avoids a lot of potential issues I thought this could be related to. Also not sure why the input comes through as an empty object. Might be some aws specific stuff happening
Mmrjack9/6/2023
I'm back now So here's a wrapper function I'm using to hack the adapter
import { APIGatewayProxyHandlerV2 } from "aws-lambda";

const charsetString = `; charset=utf-8`;


/** a filthy hack to workaround requests from Zapier where header is
* `Content-Type: application/json; charset=utf-8` */
export const hackContentType =
(fn: APIGatewayProxyHandlerV2): APIGatewayProxyHandlerV2 =>
(event, context, callback) => {
const contentType = event.headers["content-type"];
if (contentType?.includes(charsetString)) {
event.headers["content-type"] = contentType
.replace(charsetString, "")
.trim();
}

return fn(event, context, callback);
};
import { APIGatewayProxyHandlerV2 } from "aws-lambda";

const charsetString = `; charset=utf-8`;


/** a filthy hack to workaround requests from Zapier where header is
* `Content-Type: application/json; charset=utf-8` */
export const hackContentType =
(fn: APIGatewayProxyHandlerV2): APIGatewayProxyHandlerV2 =>
(event, context, callback) => {
const contentType = event.headers["content-type"];
if (contentType?.includes(charsetString)) {
event.headers["content-type"] = contentType
.replace(charsetString, "")
.trim();
}

return fn(event, context, callback);
};
I also noted that the comparisons to "application/json" didn't exist in the aws-lambda adapter But as you can see in this wrapper, adjusting event.headers["content-type"] causes createOpenApiAwsLambdaHandler to behave correctly Usage in case it's not clear
export const handler: APIGatewayProxyHandlerV2 = hackContentType(
createOpenApiAwsLambdaHandler({
router: appRouter,
createContext,
})
);
export const handler: APIGatewayProxyHandlerV2 = hackContentType(
createOpenApiAwsLambdaHandler({
router: appRouter,
createContext,
})
);
Ssachin9/6/2023
interesting quite an annoying bug i don’t think i can get around to fixing this soon anymore (will be gone for about 2 weeks) but i’ll still keep it in mind but feel free to create an issue on github, hopefully someone else will pick it up
Mmrjack9/8/2023
Thanks @sachinraja Created an issue on Github https://github.com/trpc/trpc/issues/4783

Looking for more? Join the community!

T
tRPC

charset=utf8 results in empty input

Join Server
Recommended Posts
Is there a way to alter the query key generated by trpc?I want to pass a boolean flag (`initial`) to the backend saying if it's a first call of a given procuseMutation throwing 500 errorsI've setup my next 13 app router project and started using some queries that worked fine, however thTRPC Nextjs App Router API Base URLIs there any issues with me placing trpc route handler in the root of my api folder? I don't really Turborepo, nextjs, vite react app, express serverI have following structure Apps: First Frontend - Nextjs app Second Frontend - Vite ReactApp BackenRouter/Middleware Chaining in V10Heyo, finally migrating from v9 to v10 after putting it off for a while. Is it just me, or is this mthrowing custom errors from mutationsany idea why trpc is ignoring the catch expression? it just throws its own error about unique consttrpc in a pnpm monorepoHi all 👋 I was wondering if there is a recommended setup for monorepos, in our case with pnpm workTS Error with React when creating client "useContext" collides ....when creating the client i get following error: The property 'useContext' in your router collides wType 'NextRequest' is missing properties from type 'NextApiRequest'Enviorment: Node 18, pnpm Hi, I'm facing an error, where in my app i get this error at `createTRPCCType '{}' is not assignable in server queryType '{ input: { slug: string; }; "": any; }' is not assignable to type 'string | StringFilter<"CateThe inferred type of this node exceeds the maximum length the compiler will serialize.Using HTTP:POST for `query`?Hey guys, thanks for the awesome library! My application involves making a `query` with a large amre validation on static site next js 13Hi, does any one know how to make revaluation when I’m fetching data on the server client from DB wiTransformers not transforming data (trpc-sveltekit)I'm having some trouble getting superjson to do its magic with tRPC & SvelteKit. I have a `client.tsIssue Inferring Type on Frontend with ElectroDB Query Return StatementHi all, I am using ElectroDB to work with DynamoDB, and I have a Lambda function that uses tRPC thaWrong JSON response when deployedWhen testing in localhost in dev mode there is no issue and the response is correct as expected. BuExternal callsHi! I am using T3 stack, tRPC together with clerk, and i need to create users within the app, being Need help identifying the generic client side type of proceduresHi! I think my question is better explained by what I'm trying to achive than anything else: I likIs there a way to use versioning for procedures?I want to make multiple versions (v1 / v2) for a procedure, can i do it in procedure level?createSSGHelpersI'm trying to fetch data in getStaticProps and getting the issue "Promise<{ paths: { params: { id: n