R
Railway•10mo ago
Ian

How to handle both frontend and backend hosting on Railway?

I currently have my backend deployed on Railway and my frontend deployed on Firebase. I'd like my URL structure to be as follows: mywebsite.com -> user facing website mywesbtei.com/api/* -> all the API endpoints my website will need These are two different services(React, and Python). Given that they're using URL parameters they will both need to be running inside Railway I assume? I can't have them split across service providers(Google and Railway) Is there any option besides setting up nginx(or similar) to act as a reverse proxy? Clearly, I could serve my static site at the root route of my API server but I'd prefer to not do that.
11 Replies
Percy
Percy•10mo ago
Project ID: N/A
Ian
IanOP•10mo ago
N/A
Brody
Brody•10mo ago
may I ask what's wrong with mywebsite.com for the frontend api.mywebsite.com for the backend
Ian
IanOP•10mo ago
Nothing in general and I thought about it because I could easily do it with my configuration that I already have. Partially, I have existing code that depends on the other structure. In addition, it makes the API on a different domain, which can get a little messy with auth etc. It also seems that the "general" best practice is to keep them on the same domain.
Brody
Brody•10mo ago
railway itself has the frontend and backend on different domains, so not bad practice at all. but I can understand not wanting to change code and I do know with can get tricky, just was curious is all. have a look at this, it does exactly what you want https://railway.app/template/7uDSyj make sure to use the private network! and just for the sake of thoroughness, how are you getting railway to serve your react frontend?
Ian
IanOP•10mo ago
Fair point, I might bight the bullet and switch -- as with all infrastructure/architecture decisions it seems there is not "right" answer. I haven't thought about how to have railway deploy the React.js site(it's pure react not Next). If using Caddy, could just have any attached volume that stores the "compiled" static assets vs another container with a small web server. Unless you have a better idea 😛 Thanks for your advice btw
Brody
Brody•10mo ago
create react app?
Ian
IanOP•10mo ago
At the moment yes, but will be moving to Vite
Brody
Brody•10mo ago
for vite, take a look at this template https://github.com/brody192/vite-react-template it uses nixpacks and a Caddyfile to serve the built site, no volume needed. for how your project should look like all setup, take a look a the demo reverse proxy project https://railway.app/project/35d8d571-4313-4049-9699-4e7db7f02a2f notice how neither the frontend or backend services are publicly exposed!
Ian
IanOP•10mo ago
Sweet, I'll check that one out. Thank you!
Brody
Brody•10mo ago
happy to help, let me know if you have any questions at all!
Want results from more Discord servers?
Add your server