R
Railway16mo ago
tabu

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:
its printing correctly now, but still have a cors error, i think its might actually be the /
Jump to solution
58 Replies
Percy
Percy16mo ago
Project ID: 09b9adb2-6a8b-4acd-81be-470217717e55
tabu
tabuOP16mo ago
09b9adb2-6a8b-4acd-81be-470217717e55
tabu
tabuOP16mo ago
is this something I can use for this? https://docs.railway.app/reference/private-networking
Railway Docs
Private Networking | Railway Docs
Documentation for Railway
Brody
Brody16mo ago
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
tabu
tabuOP16mo ago
yep! thank you very much
tabu
tabuOP16mo ago
Brody
Brody16mo ago
I meant sending the link to the domain lol the public domain
Brody
Brody16mo ago
okay that does work no route for / but that's not necessarily a problem okay, can you send your frontend domain
Brody
Brody16mo ago
very clean login screen btw
tabu
tabuOP16mo ago
thank you haha, its actually just a template
Brody
Brody16mo ago
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
tabu
tabuOP16mo ago
aah ok im getting a cors error rn
tabu
tabuOP16mo ago
tabu
tabuOP16mo ago
i have the cors origin set to this in railway
tabu
tabuOP16mo ago
Brody
Brody16mo ago
show me the response headers of that network request please
tabu
tabuOP16mo ago
Brody
Brody16mo ago
it doesn't look like you have any CORS middleware on your backend?
tabu
tabuOP16mo ago
it should be, heres what i have routes - cors -
tabu
tabuOP16mo ago
it works in postman and on the client in development
tabu
tabuOP16mo ago
and heres how its being called from the front
tabu
tabuOP16mo ago
and the variable for the client as well
tabu
tabuOP16mo ago
Brody
Brody16mo ago
does that check print the correct variable?
tabu
tabuOP16mo ago
no, sends nothing actually, it should print immediatly after the '======'
tabu
tabuOP16mo ago
tabu
tabuOP16mo ago
would it be the / after app in variables?
Brody
Brody16mo ago
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?
tabu
tabuOP16mo ago
oh! i think i renamed it from my config last night trying to fix it, ill try redeploying with it fixed
Solution
tabu
tabu16mo ago
its printing correctly now, but still have a cors error, i think its might actually be the /
tabu
tabuOP16mo ago
yep, thats the problem!
Brody
Brody16mo ago
all good?
tabu
tabuOP16mo ago
they are connected now it looks like cause i can create a user, but some routes still throwing cors error
tabu
tabuOP16mo ago
at the very least it does this now ^_^
tabu
tabuOP16mo ago
Brody
Brody16mo ago
missing cors headers strange
tabu
tabuOP16mo ago
does railway not support RS256?
tabu
tabuOP16mo ago
tabu
tabuOP16mo ago
Brody
Brody16mo ago
it's more likely node 16 doesn't support that node 16 is the default version railway uses, what version do you use locally
tabu
tabuOP16mo ago
im using v18.16.1 if i switched my deployment method to docker and i specify the node version, would that fix my issue?
Brody
Brody16mo ago
add engines.node: "18" to the servers package.json no need to move to a Dockerfile
tabu
tabuOP16mo ago
im very new im sorry, for script i add this?
Brody
Brody16mo ago
in your package.json
"engines": {
"node": "18"
}
"engines": {
"node": "18"
}
add that
tabu
tabuOP16mo ago
its not sending the cookies at all anymore
tabu
tabuOP16mo ago
tabu
tabuOP16mo ago
do i need it for the frontend as well?
tabu
tabuOP16mo ago
same errors from the server
tabu
tabuOP16mo ago
i added a consolelog to check node version and it is running 18 now
tabu
tabuOP16mo ago
tabu
tabuOP16mo ago
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
Brody
Brody16mo ago
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
tabu
tabuOP16mo ago
where would u recommend putting them? no worries! I appreciate the help! Im happy its able to connect now and create users ^_^
Brody
Brody16mo ago
generate them on startup?
tabu
tabuOP16mo ago
aah ok, Ill look into how to do that! thank you very much!
Brody
Brody16mo ago
no problem 🙂
Want results from more Discord servers?
Add your server