How do I expose a simple health check endpoint in ...
# javascript
h
How do I expose a simple health check endpoint in a KotlinJS react app? Something like
Copy code
app.get('/health-check',(req,res)=> {
  res.send ("OK");
});
c
What do you mean exactly? React is a client-side framework, it doesn't really expose endpoints?
h
I want to check the liveness of the KotlinJS React app. The example is from here: https://stackoverflow.com/questions/56106263/how-to-set-kubernetes-probes-for-react-app
c
As this comment mentions, a React app isn't a web server. It runs client-side, so if the server is down, it just doesn't exist.
How is your app hosted?
h
In a k8s container
c
What's the web server?
h
It's an nginx.
c
Search for how to do a readiness check for nginx, then
h
I see, the probe is a simple
get
that will never 'start' the web-app. All it will ever get is the html body as an answer.
c
A probe is a request that checks the status of some external service. A React app is entirely client-side, it means nothing to check its status. e.g. if your client closes their browser, the app dies. But should that mean the app is dead on k8s? No, maybe other clients have it running on their machines. Most of the time, React apps are distributed by a web server somewhere. Now, a web server is an external service, so it may make sense to create a probe against it. Since you're using nginx, you may install a probe that checks nginx's status. But what you're testing is whether the distribution of the app is working, you can't test if the app itself is working. (and thus, it's an nginx question and not a Kotlin/JS question, since it's the same answer no matter what your nginx is distributing)
I don't know anything about nginx, so I can't help further, good luck 🙏
h
Yeah, that was my understanding as well, thank you for the detailed explanation. We have it running now, seems like just configuring a
httpGet
on
/
with k8s is enough.