hobby

Hello, I'm trying to use the Healthcheck func but it keeps failing with a 400. When I'm not doing the healthcheck and test the enpoint it returns 200.
Solution:
Alright, if think I got it... It's indeed an ALLOWED_HOSTS issue. I just put * and the healthcheck worked correctly. Since railway's checking IP might change, I'll have to use something else....
Jump to solution
31 Replies
Percy
Percy14mo ago
Project ID: d6a04e84-91e3-4e5a-94eb-11dae5cca406
iwHiteRabbiT
iwHiteRabbiTOP14mo ago
d6a04e84-91e3-4e5a-94eb-11dae5cca406
Floris
Floris14mo ago
hey man could you send me the code responsible for your /health endpoint?
iwHiteRabbiT
iwHiteRabbiTOP14mo ago
Sure (Django ViewSet) @action(detail=False, methods=['get'], url_path='check') def check(self, request): return Response(status=status.HTTP_200_OK) https://fairmarket-back-staging.up.railway.app/market/api/health/check/
Floris
Floris14mo ago
do you have a custom healthcheck path configured in railway? i'm fairly certain it defaults to '/health' and by the looks of it your endpoints open on '/check' deploy > settings
iwHiteRabbiT
iwHiteRabbiTOP14mo ago
I removed it for now since it wasn't working. I did put "/market/api/health/check/" Which gave me the error 400 Build log: Attempt #14 failed with status 400. Continuing to retry for 27s 1/1 replicas never became healthy! Deploy log: [03/Oct/2023 13:17:27] "GET /market/api/health/check/ HTTP/1.1" 400 143 If I remove the healthchek and test the endpoint: [03/Oct/2023 14:01:40] "GET /market/api/health/check/ HTTP/1.1" 200 6168
Adam
Adam14mo ago
/health/check isn’t what they asked you to do, check on /health instead
iwHiteRabbiT
iwHiteRabbiTOP14mo ago
Isn't it supposed to be an example of endpoint? I put '/' on my front and it's working...
Adam
Adam14mo ago
I don’t follow
iwHiteRabbiT
iwHiteRabbiTOP14mo ago
What would be the point of having a textfield where you put your own endpoint if you have to put /health...?
Floris
Floris14mo ago
i dont think you understand how endpoints work
Adam
Adam14mo ago
you didn’t indicate that you changed that setting, just that you were using /health/check in your code. If you’re having issues getting it to work, it’s best to set everything to default and build off there
Floris
Floris14mo ago
just put /health in django and look what railway defaults to and go from there it is just telling railway where to find the entry of your health protocol if you have 100s of endpoints its impossible for railway to check all before deploying
Adam
Adam14mo ago
I think they get it
Floris
Floris14mo ago
my bad
iwHiteRabbiT
iwHiteRabbiTOP14mo ago
hmmm I DID put /market/api/health/check/ in the setting, then redeployed, then SAW railway asking for the RIGHT end point (cf the logs I just shared above). It didn't return a 404 but a 400. It could be a CORS error, probably is actually... But since I can't see from whom the request for that endpoint is coming it's hard to tell.
Floris
Floris14mo ago
interesting, would you feel comfy sharing your repo so i can reproduce and fix it that way
Adam
Adam14mo ago
You can see the source ip by checking the header X-Forwarded-For
iwHiteRabbiT
iwHiteRabbiTOP14mo ago
I'd rather not ^^. Don't you have a Django backend template that you could quickly test?
Floris
Floris14mo ago
probably, let me check railway templates i usually opt for FASTapi
Adam
Adam14mo ago
Here ya go
Floris
Floris14mo ago
thanks adam!
Adam
Adam14mo ago
no prob
iwHiteRabbiT
iwHiteRabbiTOP14mo ago
On railway logs?
Adam
Adam14mo ago
No, a header on the incoming request
Solution
iwHiteRabbiT
iwHiteRabbiT14mo ago
Alright, if think I got it... It's indeed an ALLOWED_HOSTS issue. I just put * and the healthcheck worked correctly. Since railway's checking IP might change, I'll have to use something else.
iwHiteRabbiT
iwHiteRabbiTOP14mo ago
FYI, the enpoint is "/market/api/health/check/" 😉
iwHiteRabbiT
iwHiteRabbiTOP14mo ago
That issue will hit everyone using Django and setting ALLOWED_HOSTS correctly >< I will try this suggested solution from StackO: https://stackoverflow.com/questions/27720254/django-allowed-hosts-with-elb-healthcheck Maybe Railway could mention this in their doc somewhere for future Django users (I mean the solution)
Stack Overflow
Django ALLOWED_HOSTS with ELB HealthCheck
I have a django application deployed on Elastic Beanstalk. The HealthCheck for my app keeps failing because the IP of the ELB HealthCheck is not included in my ALLOWED_HOSTS settings variable. Ho...
Brody
Brody14mo ago
railways healthchecks come from an internal local ipv4 ip address
iwHiteRabbiT
iwHiteRabbiTOP14mo ago
Hence the 400 😉
Want results from more Discord servers?
Add your server