Questions and discussions about using the Shopify CLI and Shopify-built libraries.
We have created an app with node template using:
```
npm init @Shopify/app@latest
```
It seems to have been made exceptionally hard to modify the routes of this template application to have a simple health check endpoint like `/healthz`, which responds with HTTP 200. This is usually a requirement with load balancing services like Azure Front Door to distribute our app globally.
Could you provide an easy way to do this or even include it into your templates?
I would imagine this to be especially necessary when using Shopify App Bridge, where the app can handle calls by the store front.
Solved! Go to the solution
This is an accepted solution.
Hi Aviita,
It should be as simple as adding this to server/index.js:
app.get('/healthz', (req, res) => {
res.status(200).send();
});
Have a look at the expressJS documentation for more examples of how to create routes.
This is an accepted solution.
Hi Aviita,
It should be as simple as adding this to server/index.js:
app.get('/healthz', (req, res) => {
res.status(200).send();
});
Have a look at the expressJS documentation for more examples of how to create routes.
Could have put in more details. Been trying this and it gets hijacked by other middleware:
app.use("/api/healthz", (req, res, next) => {
console.log(`Health check endpoint called`);
res.status(200).send({ success: true });
});
And same with that `/healthz`, and this is with plain App I just created to ensure our app that has seen some development (different message though than with `/api/healthz`.
Placed it just above the `/*`:
app.use("/healthz", (req, res, next) => {
console.log(`Health check endpoint called`);
res.status(200).send({ success: true });
});
app.use("/*", async (req, res, next) => {
Ha, it actually does work when deployed to server. Just some problem with my localhost setup. Thanks for inserting some more hope in me. 🙂
And additionally see that I slipped into registering my endpoint as middleware instead of get endpoint, but that was my attempt to ensure it would get precedence over other middleware.
But I verified now that on server both solutions work.