a year ago
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.
0 Replies
a year ago
may I ask what's wrong with[mywebsite.com](mywebsite.com)
for the frontendapi.[mywebsite.com](mywebsite.com)
for the backend
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.
a year 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
make sure to use the private network!
a year ago
and just for the sake of thoroughness, how are you getting railway to serve your react frontend?
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 😛
a year ago
create react app?
a year ago
for vite, take a look at this 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
notice how neither the frontend or backend services are publicly exposed!
a year ago
happy to help, let me know if you have any questions at all!