mrjack
mrjack
TtRPC
Created by mrjack on 9/4/2023 in #❓-help
charset=utf8 results in empty input
Created an issue on Github https://github.com/trpc/trpc/issues/4783
27 replies
TtRPC
Created by mrjack on 9/4/2023 in #❓-help
charset=utf8 results in empty input
Thanks @sachinraja
27 replies
TtRPC
Created by mrjack on 9/4/2023 in #❓-help
charset=utf8 results in empty input
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,
})
);
27 replies
TtRPC
Created by mrjack on 9/4/2023 in #❓-help
charset=utf8 results in empty input
But as you can see in this wrapper, adjusting event.headers["content-type"] causes createOpenApiAwsLambdaHandler to behave correctly
27 replies
TtRPC
Created by mrjack on 9/4/2023 in #❓-help
charset=utf8 results in empty input
I also noted that the comparisons to "application/json" didn't exist in the aws-lambda adapter
27 replies
TtRPC
Created by mrjack on 9/4/2023 in #❓-help
charset=utf8 results in empty input
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);
};
27 replies
TtRPC
Created by mrjack on 9/4/2023 in #❓-help
charset=utf8 results in empty input
if need be
27 replies
TtRPC
Created by mrjack on 9/4/2023 in #❓-help
charset=utf8 results in empty input
n.b. I'm on Yarn 3 which has it's own patch package system. I can just do a patch manually though
27 replies
TtRPC
Created by mrjack on 9/4/2023 in #❓-help
charset=utf8 results in empty input
I'm just in a meeting right now - I'd be happy to give it a crack in about 1h
27 replies
TtRPC
Created by mrjack on 9/4/2023 in #❓-help
charset=utf8 results in empty input
Thanks @sachinraja ❤️
27 replies
TtRPC
Created by mrjack on 9/4/2023 in #❓-help
charset=utf8 results in empty input
I found a few string comparisons to "application/json" in the codebase - I thought that might be it
27 replies
TtRPC
Created by mrjack on 9/4/2023 in #❓-help
charset=utf8 results in empty input
@sachinraja - a penny for your thoughts?
27 replies
TtRPC
Created by mrjack on 9/4/2023 in #❓-help
charset=utf8 results in empty input
Note I'm using adapters/aws-lambda
27 replies