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
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.
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 exportOh 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
Can you share the contents of your
http.ts
file?Yes, http.ts is deploying but president.ts is not
Maybe the export modifier is necessary in president.ts
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
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