Matt Luo
Matt Luo12mo ago

Is all code for HTTP actions organized into one big http.ts file?

I am trying to create a new HTTP action about US presidents. I created a file named presidents.ts with the HTTP action logic inside my /convex directory. But this HTTP action is never deploying: I don't see the action in my Functions console, and my front end gets a fetch error. If I'm interpreting these docs literally: https://docs.convex.dev/functions/http-actions it would seem that all HTTP actions are defined in a single file http.ts. Is that truly correct?
8 Replies
Matt Luo
Matt LuoOP12mo ago
I was able to resolve this error by appending my logic about president http actions inside the http.ts file. But now the http.ts file is pretty big.
lee
lee12mo ago
you can define the httpAction in any file (in that docs page, it defines the action in convex/myHttpActions.ts and convex/messages.ts). the thing that needs to be in http.ts is the router as the default export
Matt Luo
Matt LuoOP12mo ago
Oh I see, so then my deployment of president.ts has failed The curl command failed in my local VS Code terminal (I changed the URL for my own dev environment URL) curl -X GET https://happy-animal-123.convex.site/test No matching routes found even though my http.ts definitely works Where am I supposed to run the curl command to test my HTTP actions? I assume I am able to run it in my VS Code terminal, since a local run of my app is successfully getting data from the http actions in http.ts curl -X GET https://happy-animal-123.convex.site/test
RJ
RJ12mo ago
Can you share the contents of your http.ts file?
Matt Luo
Matt LuoOP12mo ago
Yes, http.ts is deploying but president.ts is not
Matt Luo
Matt LuoOP12mo ago
Maybe the export modifier is necessary in president.ts
lee
lee12mo ago
It looks like president.ts is defining a new httpRouter. You should define only the httpActions in there, and import them into http.ts to add them to the router
Matt Luo
Matt LuoOP12mo ago
Oh interesting, I did not understand this HTTP action and router relationship. At this point, Let me mark this support thread as resolved and do some more research. I just asked the Convex AI Bot: does a typical convex project have multiple HTTPRouter defined? No, a typical Convex project does not have multiple HTTPRouters defined. -- So, I need to learn more about the purpose of this HttpRouter overhead

Did you find this page helpful?