Domain needed for backend?

I have a probably stupid question, but here goes anyway. This is only my second day on Render and I’m trying to deploy my first MERN app. I have been using Firebase for years, so everything is all-in-one, and now I am trying to separate the client/server code. I had issues all day yesterday trying to deploy from CORS to Environment variables. I think I have it all worked out now, but I am getting an error now:

Failed to load resource: net::ERR_NAME_NOT_RESOLVED

Near as I can figure, and have verified, all the correct data is being sent to the backend, but the backend is not being found. I have a custom domain setup as well and used mydomain dot com as the frontend (setup as a static website on render) and am trying to use mydomain-api.com for the backend (setup as a web service on render). The frontend displays in the browser just fine, but I cannot call any functions on the backend without getting the error above. So, my stupid question is: Does the mydomain-api.com (web service) need it’s own registered domain and DNS pointing to it?

I think that is the problem, but not exactly sure.
Thank you

Hello,

If you wanted to access your API using mydomain-api.com as opposed to the *.onrender.com the domain you would need to register a custom domain for your API.

That being said since your frontend app and API are the same logical application, the canonical approach (which would also avoid CORs altogether for your API requests) would be to register a custom domain for your API that matches the domain of your frontend site (i.e. if your frontend is mydomain.com, you could configure your API with something like api.mydomain.com, as opposed to mydomain-api.com).

An alternative approach would be to add a /api route to your frontend application and add a rewrite rule to send those requests to your backend service. You can see an example of this here: https://github.com/johnbeynonorg/render-monorepo-example.

I hope that helps.

Best Regards,

Matt

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.