Communicate backend with frontend in railway
I have an app in railway that has 2 parts, the front and the backend
(PHOTO 1)
The backend tells me to use that to communicate internally
(PHOTO 2)
This is my code in frontend:
And this my backend :
and this is my index.js from my backend , its runs by a nodemon
31 Replies
Project ID:
N/A
What do I have to use to communicate with the backend from the front? I try with:
'http://backend.railway.internal:3001/auth/login',
'https://backend.railway.internal:3001/auth/login',
'http://backend.railway.internal/auth/login',
'http://backend/auth/login',
'https://backend/auth/login',
'backend/auth/login',
And nothing, what am I doing wrong?
Project ID:
99233283-dda8-4de0-8f5e-52189f3955db
this is a CSR frontend app?
A mern app , backend in node.js with connection to a mongodb atlas , frontend in react
Note i use
CI=false npm run build
to build the frontend because yarn run build give erros because axios
Sorry, I don't have that much knowledge if it is crs.sorry, i dont know why i used an acronym, csr is client side rendered, is that the type of app your frontend is?
I was researching and it uses CSR because react use ReactDOM
sounds good, then you need to call a public backend domain, to get that head to the backend's service settings and click generate
i generate a public domain in my backend to test
in my login page , i write >
why as a test? give it a proper name
to test jaja I was fighting all day with 500 tests haha
its okey?
do not specify a port, you can only access your app over 443
ah thats good to know
in my backend the app have to listen 443 port?
and since you are using the https scheme, you also dont need to specify 443, since thats implied when using https
nope, your backend app needs to listen to process.env.PORT
please read this
https://docs.railway.app/troubleshoot/fixing-common-errors
A lots of thanks brody
u help me a lot
side note, can you send me your package.json for your frontend app?
nobleza obliga
is that your full frontend package.json
yes
where the start script
sorry
please read and apply this guide to your frontend
https://help.railway.app/project-help/f9v3gkPQRy4UShk5SnoPDH/getting-your-create-react-app-running-on-railway/qHRsgxa5n57xLp1yVgk9fP
i will , and another question , if my post in the frontend is
and i restructure my index.js in the backend to this >
I can use port 3001 with the variable in railway?
ah sorry i should have mentioned that, my bad
you do not need to (and should not) set a PORT in the service variables when your app listens on PORT as railway generates one for you automatically
So this line
// Use PORT provided in environment or default to 3001
const port = process.env.PORT || 3001;
to
// Use PORT provided in environment or default to railway decided
const port = process.env.PORT;
right?nope, what you had was correct, no need to change that
please read my message again
How did you configure the allowed IP addresses in MongoDB Atlas? Did you choose 'allow all' or did you specify a specific IP address range for Railway?
allow all , @Brody again me jaja , how i could find the ip from railway to whitelist in mongo?
you would need to allow all, as deployments on railway have dynamic ips, and you could end up with any one of the thousands of ips for the region
but anyway, did you get your frontend and backend working? you never follow up?
Hi , thnk for the aswer , its already working
perfect!