cabyambo
cabyambo3w ago

How to pass the http request object as an argument

I have to use node libraries when performing operations within my http action, so for this reason I've pulled out the code that will run in the node runtime into an action that live in file with the use node directive. I call the node action from within the http action, but need to pass the request object to the node action.
convex/myFunctions.ts

export const myHttpWrapperFunction = httpAction(async (ctx, request) => {
const computedValueThatRequreisNodeDependencies = ctx.runAction(
internal.node.functins.myAction,
{request: request}
);
});
convex/myFunctions.ts

export const myHttpWrapperFunction = httpAction(async (ctx, request) => {
const computedValueThatRequreisNodeDependencies = ctx.runAction(
internal.node.functins.myAction,
{request: request}
);
});
In my node action I accept the args as follows:
args: {
request v.any()
}
args: {
request v.any()
}
When I do that however I get a type error. It looks like Convex can not serialize the request object and pass it as a method param. Is there a best practice here?
Convex type (present at path .request in original object {\"request\":{}}). To learn about Convex's supported types, see https://docs.convex.dev/using/types.",
"trace": "Uncaught Error: Request {} is not a supported Convex type (present at path .request in original object {\"request\":{}}). To learn about Convex's supported types, see https://docs.convex.dev/using/types.\n
Convex type (present at path .request in original object {\"request\":{}}). To learn about Convex's supported types, see https://docs.convex.dev/using/types.",
"trace": "Uncaught Error: Request {} is not a supported Convex type (present at path .request in original object {\"request\":{}}). To learn about Convex's supported types, see https://docs.convex.dev/using/types.\n
2 Replies
erquhart
erquhart3w ago
Convex function arguments and return values must be serializable, so you can’t pass in a request object. What I’ve done in these scenarios is pass the parts I need that are serializable, like headers, and create a new request in the function with that data.
cabyambo
cabyamboOP3w ago
I see. Thank you

Did you find this page helpful?