cabyamboC
Convex Community5mo ago
2 replies
cabyambo

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}
  );
});


In my node action I accept the args as follows:
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
Was this page helpful?