Cannot reach my API with private network address
I want to send an http request to my api on railway from my frontend application which is also deployed on railway. however, I am getting following error:
POST https://rental_management_api/v1/auth/login/server/admin net::ERR_NAME_NOT_RESOLVED
my backend uses port number 443 and it's internal address is rental_management_api
17 Replies
Project ID:
010de26b-7fea-49a2-8845-1072c6586444
010de26b-7fea-49a2-8845-1072c6586444
what kind of frontend app is this
next-js application
and you are making these requests from the sever side of the frontend, correct?
yes
my api responds when I make a request to it's external address
have a look at this guide page, it should tell you everything you need to know - https://docs.railway.app/guides/private-networking
but of course if you need any clarification feel free to ask!
I guess the reason why my code doesn't work is that I don't listen for ipv6 addresses in my api code
that could be one reason, but i can tell you right now the url you are trying to fetch is wrong
that guide page talks about what the proper internal url would look like
ok I see. Thank you sm. I will fix that and see if it works
I corrected my address as follows: http://rental_management_api.railway.internal:443/v1/auth/login/server/admin
I am getting following error this time:
Mixed Content: The page at 'https://rentalmanagementadminpanel-production.up.railway.app/' was loaded over HTTPS, but requested an insecure resource 'http://rental_management_api.railway.internal:443/v1/auth/login/server/admin'. This request has been blocked; the content must be served over HTTPS.
thats an error you would get from a browser
you can't make a request to the private network from the users browser, wouldnt be much of a private network if so
yeah I see. Then how should I procede. I just want to deploy my front-end and my api on railway and establish communication between them. I am trying to the end-points of my api on railway from my front-end application
should I just use my api's external address?
yes you would have to use the external address
so little correction with the information you have given me thus far, you meant to say no
sorry for the confusion. I miss understood and thank you for the answer
no worries, happy to help
I am getting following error this time:
Access to fetch at 'https://rentalmanagementapi-production.up.railway.app/v1/auth/login/server/admin' from origin 'https://rentalmanagementadminpanel-production.up.railway.app' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
you would need to setup cors in your backend