How do I link my services internally?
Hello, I tried to figure it out on my own, but I have just ended up losing sleep haha. I'm having an issue connecting my frontend and my api. Its related to the env variables but everything I've tried has failed. I do not understand how to expose my api or my client's port to each other on railway. I have also looked into the private networking feature, but in the docs its not clear how to actually implement it. I'm pretty much completely lost at this point on what to do.
Here is my repo: https://github.com/TabuHana/Store-CMS-TS
I have an env variable in /server called origin set up that is suppose to be the url for my client for cors and I have a similar env variable in /client that needs the url for my server. I tried:
1. adding a variable 0.0.0.0:$PORT, this does nothing, as well as doing ::client to try and set up for the private network and that didnt work. I think I'm setting it up incorrectly, but the docs arent clear...
2. added the custom domain from railway and I get a cors error
I linked imgs to how I currently have the needed variables set up in railway. If I need to provide anymore info, please let me know. Sorry for another dumb question, I'm losing a lot of sleep trying to figure this out. Hope you guys have a great day ❤️
GitHub
GitHub - TabuHana/Store-CMS-TS: A fully typed CMS store built with ...
A fully typed CMS store built with small businesses. Track your orders, customers and products with ease! - GitHub - TabuHana/Store-CMS-TS: A fully typed CMS store built with small businesses. Trac...
Solution:Jump to solution
its printing correctly now, but still have a cors error, i think its might actually be the
/
58 Replies
Project ID:
09b9adb2-6a8b-4acd-81be-470217717e55
09b9adb2-6a8b-4acd-81be-470217717e55
is this something I can use for this? https://docs.railway.app/reference/private-networking
would you mind sending the backends domain so I don't have to write it out 🙂
we will tackle the backend first, one service at a time
yep! thank you very much
I meant sending the link to the domain lol
the public domain
oh lol yes sorry
https://store-cms-server-dev.up.railway.app/
okay that does work
no route for / but that's not necessarily a problem
okay, can you send your frontend domain
very clean login screen btw
thank you haha, its actually just a template
show me the errors you get in the browsers
also just like to point out private networking has no application for your case of frontend to backend communication
aah ok
im getting a cors error rn
i have the cors origin set to this in railway
show me the response headers of that network request please
it doesn't look like you have any CORS middleware on your backend?
it should be, heres what i have
routes -
cors -
it works in postman and on the client in development
and heres how its being called from the front
and the variable for the client as well
does that check print the correct variable?
no, sends nothing actually, it should print immediatly after the '======'
would it be the
/
after app in variables?I looked at the default and custom files in the config folder, and I can't see how they are loading the config values from the environment?
oh! i think i renamed it from my config last night trying to fix it, ill try redeploying with it fixed
Solution
its printing correctly now, but still have a cors error, i think its might actually be the
/
yep, thats the problem!
all good?
they are connected now it looks like cause i can create a user, but some routes still throwing cors error
at the very least it does this now ^_^
missing cors headers
strange
does railway not support RS256?
it's more likely node 16 doesn't support that
node 16 is the default version railway uses, what version do you use locally
im using v18.16.1
if i switched my deployment method to docker and i specify the node version, would that fix my issue?
add
engines.node
: "18" to the servers package.json
no need to move to a Dockerfileim very new im sorry, for script i add this?
in your package.json
add that
its not sending the cookies at all anymore
do i need it for the frontend as well?
same errors from the server
i added a consolelog to check node version and it is running 18 now
I've edited my variables to this -> it gets rid of the error in the server, but the cookies are back to being sent how they were before so cors error again
okay well this error wouldn't be specific to railway, if you do some research and find some answers I'd be happy to help you implement them on railway
I would advise against putting a cert file into the service variables
where would u recommend putting them?
no worries! I appreciate the help! Im happy its able to connect now and create users ^_^
generate them on startup?
aah ok, Ill look into how to do that! thank you very much!
no problem 🙂