R
Railway

✋|help

Hosting Django backend and React frontend from the same Domain

Ttonquin8/27/2023
I have two services, one for my backend and one for my frontend. They currently have two separate domains. I've been having some headache handling things like http only cookies so far... So, after doing some research (googling) I see that some people use NGINX to route requests to either the backend or frontend, and it all works under the same domain. Does anyone have advice for accomplishing this? Not sure if this is more work than dealing with the separate frontend/backend domains. Any advice is much appreciated 🙂
Ttonquin8/27/2023
N/A
Bbrody1928/27/2023
do I have the template for you https://railway.app/template/7uDSyj
Ttonquin8/27/2023
Wow this looks amazing, thank you so much!!! ❤️
Bbrody1928/27/2023
no problem, be sure to read the overview very closely
Ttonquin8/27/2023
Okay I think I have it set up pretty well! I am able to login and cookies get set correctly now, then able to hit my authenticated route and it returns data correctly.

I am wondering if it's possible to access Django's admin view. I would like to have it in for now so I can set up some stuff to try to get my "Sign in with Google" working. I commented out the admin line in the Caddy file but still doesn't seem to let me log in. Also, if I go to the /admin route on the Caddy service it just takes me to the regular landing page.
Bbrody1928/27/2023
well that caddyfile is not a one size fits all solution by any means, that would be impossible, but lets see what you have for your current caddyfile
Ttonquin8/27/2023
I don't think I changed anything from what you provided
Ttonquin8/27/2023
other than commenting the admin line for now
Bbrody1928/27/2023
what admin line?
oh no that admin has absolutely nothing to do with django, that's caddy's admin thing, don't touch that please
Ttonquin8/27/2023
ohhhhhhh woops 😮
Bbrody1928/27/2023
one would think a comment on every line would be sufficient explanation 😉
Ttonquin8/27/2023
u underestimate my ability to misunderstand 🙂
Bbrody1928/27/2023
either way, if you want to proxy requests from /admin to the backend's /admin route you would need to add a reverse_proxy directive to handle that, there's a link to the docs for reverse_proxy in the template overview or readme file
Ttonquin8/27/2023
hmm okay, I will try to look into that a bit more. I can access the admin route if I go to the backend service, just seems like there are no styles cause my static files don't seem to be loading properly. Also doesn't seem to redirect me to the admin panel once I log in as a super user. Maybe trying to figure that out first is the better play though 🤔
Bbrody1928/27/2023
yeah common issue with improperly setup django apps
Ttonquin8/27/2023
Any idea if that's something wrong with how I set static up here or something else
Bbrody1928/27/2023
no clue I'm not a django dev lol
but are you running collect static in your start command?
Ttonquin8/27/2023
Yep
Ttonquin8/27/2023
Bbrody1928/27/2023
I'm out of ideas then, sorry
Ttonquin8/27/2023
All good, you have helped a ton already!! Really appreciate it, thanks
Bbrody1928/27/2023
no problem 🙂
I'll still be around to help you with the proxy admin thing when you sort out the missing styles, though I do wanna see you attempt to add the proxy yourself since you wouldn't learn much if I did it for you 🙂
Ttonquin8/27/2023
of course, I will do my best to get that done on my own!!!
Bbrody1928/29/2023
well how did it go!?
Ttonquin9/17/2023
hey, so sorry for not ever responding to this! I got distracted with starting a new job and only have time to work on this on weekends im free. Just looking at it again for the first time this weekend. I ended up getting the styles working for the admin section which I think was just an issue with how I set up the static files.

I'm trying to get my local development setup running right now with the proxy and also trying to set up a dev environment on railway. Just interested in getting a solid development "pipeline" going if that makes sense
Bbrody1929/17/2023
ah gotcha, well I wish you luck!
Ttonquin9/17/2023
thanks!! 🙂
Ttonquin9/17/2023
Having a bit of struggle getting things set up locally...

I create a docker image:
docker build -t caddy-proxy .

Run a container from the image with PORT, FRONTEND_HOST, BACKEND_HOST added (1st image).

Go to localhost:8080 and get a empty response error (2nd image).

Verified that my backend and frontend are both running correctly on the right port
Ttonquin9/17/2023
Any help appreciated as always but i know its been a super long time since this thread was started lol
Bbrody1929/17/2023
try replacing localhost with http://127.0.0.1
also these highly cropped screenshots are not doing you any favours
Ttonquin9/17/2023
hmm still seem to be having the same issue
Ttonquin9/17/2023
Ttonquin9/17/2023
Bbrody1929/17/2023
can you show me that you can access the frontend and backend via those urls you have set in those variables
Ttonquin9/17/2023
Bbrody1929/17/2023
and show me trying to access those same pages from the proxy
Ttonquin9/17/2023
Bbrody1929/17/2023
please stop using localhost lol
Ttonquin9/17/2023
sorry :/
Bbrody1929/17/2023
now show me trying to access the backend through the proxy
Ttonquin9/17/2023
1st image: accessing it directly from backend url
2nd image: trying to access it from proxy
Bbrody1929/17/2023
does this work on railway
Ttonquin9/17/2023
yeah it does
Bbrody1929/17/2023
well then I have no clue, you're doing something wrong locally, and I have never used docker locally
honestly you should throw out the whole proxy thing and just do two separate services, this proxy stuff is adding too much complexity
Ttonquin9/17/2023
ya fair lol. I was mostly using the proxy so I could get auth tokens to be stored as http only cookies which seemed to only work if backend/frontend were served from the same domain. Think maybe thats overkill/too much hassle for me at this point
I appreciate all your help! Thanks again.
Bbrody1929/17/2023
there is some funky stuff with cookies when you go across different domains, but an hour's worth of good research on that topic and you won't have any mor issues
Ttonquin9/17/2023
kk ill take a closer look at that instead!
Bbrody1929/17/2023
sounds good

Looking for more? Join the community!

R
Railway

✋|help

Join Server
Recommended Posts
Response Pending with OpenAIHi I have SAAS website running on Railway using OpenAI with Next js , the problem is the endpoint noDjango backend fails to respondWhen I click on the url for my django backend (I am using react frontend in a separate service) I geReflexHi, someone deploy reflex.dev in railway? do you have a guide?The new log explorer is great, Is it possible to show the service name in there ?Currently in the log explorer the service name is an ID and I was wondering if you plan to show the What is a good / recommended resource use for a web app? Plus question about scaling.I am deploying a few applications for a client of mine. It is a multi-tenant app made in sveltekit. How to put site on maintenance mode in railway?hello everyone how do i put a site on maintenance mode in railway or 'page can not be reached' mode Service not updating to Hobby specshey! I don't know if I'm doing something wrong but I paid for the hobby plan but my service still haerror on index fileI have an index file in a folder that exports all the components in that folder for easier importinOdoo Community EditionI would like to know if we can setup Odoo in railway? The odoo image is built with docker using thiWebsocket disconnectingHey, I have an app that uses a websocket (hosted on railway) but for some reason every once in a whinpm WARN config production Use `--omit=dev` instead when trying to start Nestjs appI'm trying to deploy my app (https://github.com/Omniforce-Technologies/omniforce-asset-store/tree/deDjangoHello good people of Railway! I would like to ask for a bit of help and advice about Django deploymeI have a custom domain from SuperHostingI have this doman briefeats.eu and I want to configure it to point to my angular app Currently I haDNS settings not being accepted by domain host.I'm finalizing a deployment of a React.js frontend only site, I got the green confirmation of the siWinston logs not appearing in deployment logsIn my node.js deployment if I do a console.log it appears normally in deployment logs, but using windeploy logs say nuxt "start" is an unknown command. Production and development sites both crashed.😫CMD Line accessI freaking swear I hate this so much I JUST WANT TO BE ABLE TO USE THE COMMAND LINE <:sadcat:7868689Laravel cron jobsHow can I run php artisan schedule:work every minute?Postgres drops connection when inactive, is this by default?I'm developing a node app using AdonisJS@5 and on a prolonged inactivity period (more than 5 hours) Fontconfig to canvasHi, I've been using the node-canvas in default railway when I use that, only libuuid and libGL are i