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:Jump to 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....
31 Replies
Project ID:
d6a04e84-91e3-4e5a-94eb-11dae5cca406
d6a04e84-91e3-4e5a-94eb-11dae5cca406
hey man could you send me the code responsible for your /health endpoint?
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/
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
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
/health/check isn’t what they asked you to do, check on /health instead
Isn't it supposed to be an example of endpoint?
I put '/' on my front and it's working...
I don’t follow
What would be the point of having a textfield where you put your own endpoint if you have to put /health...?
i dont think you understand how endpoints work
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
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
I think they get it
my bad
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.
interesting, would you feel comfy sharing your repo so i can reproduce and fix it that way
You can see the source ip by checking the header
X-Forwarded-For
I'd rather not ^^.
Don't you have a Django backend template that you could quickly test?
probably, let me check railway templates i usually opt for FASTapi
Here ya go
thanks adam!
no prob
On railway logs?
No, a header on the incoming request
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.
FYI, the enpoint is "/market/api/health/check/" 😉
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...
railways healthchecks come from an internal local ipv4 ip address
Hence the 400 😉