IdanB
IdanB16mo ago

Yo guys,

Yo guys, I'm having a convex action which calling my backend running locally on port 1342, I try to GET some resources from the backend using axios, so I've added the "use node" at the top of the action file, when calling my backend with axios.get I get an ECONNREFUSED, I guess it has something to do with CORS? Please note my backend is configured to handle requests from all ports (*). When hitting the backend endpoint with regular next.js route handlers it works fine, as well as when just pasting the url of the backend in browser. For some reason I get an error when using convex action. Any help is highly appriciated, Thank you,
6 Replies
nipunn
nipunn16mo ago
Hello. Can you provide the relevant code inside the action? My guess is that because you're trying to access something like localhost:1342 from a Convex action, it's unable to reach it, because the Convex action is running in the cloud. My mental model based on what you're describing is that you have Frontend -> Convex Action (Primary backend) -> Secondary Backend There's a pretty cool tool ngrok (https://ngrok.com/) - which can help you get around this - it'll give you a public internet address for your localhost secondary backend so it can be accessed from the action. Does this help? I may be misunderstanding your setup.
ngrok | Unified Application Delivery Platform for Developers
ngrok is a secure unified ingress platform that combines your global server load balancing, reverse proxy, firewall, API gateway and Kubernetes Ingress Controller to deliver applications and APIs.
philipsman
philipsman16mo ago
@IdanB share your github repo link or share the code using openbin.dev cli
IdanB
IdanBOP16mo ago
@nipunn Thats exactly what I thought, is there a way to overcome it without exposing the BE (backend) to the web? The FE (frontend) is used primarily for an inner tool for a development team, the FE is communicating with the BE and I want to keep the BE secure and private as much as possible. @philipsman Thank you for your help, but I cannot share it, it is a close source private project, but I'll just focus on what's matters here, which is my my convex action doing something like this: const res = await axios.get("http://localhost:1342/v1.....")
nipunn
nipunn16mo ago
Could you describe more of your stack? I'm not fully understanding what you have / what you're going for. For context, Convex functions (including actions) run in the Convex cloud (eg flying-fish-123.convex.cloud), so similar to other services that run functions in the cloud (AWS lambda, cloudflare workers, etc), you cannot do await axios.get("http://localhost:1342"). My understanding is that you want something like this FE(next/vite web app running on localhost?) -> Convex(convex.cloud) -> BE(localhost:1342) How do you envision you want your stack to work? Which parts do you want running locally on your machine vs in the cloud?
philipsman
philipsman16mo ago
Sharing one file won't risk anything
nipunn
nipunn16mo ago
Hey @philipsman - I appreciate your enthusiasm jumping in to be helpful. We love that attitude around here. However, there's no need to pressure other members of the community into sharing code that they're not comfortable sharing. They might have requirements that you're not familiar with. Private code is a totally reasonable thing which we can be understanding of. Let's just try and be helpful!

Did you find this page helpful?