"""
First, make sure your webserver has an endpoint (e.g. /health) that will return a response with HTTP status code 200 when your application is live and ready. If your application needs to do some initialization on startup (running database migrations, populating cache, etc.), it's a good idea to return a non-200 status code from your endpoint until the initialization completes.
"""
Example
export function health() {
http.server.on("request", async (req, res) => {
if (!req.url) return;
const params = new URLSearchParams(req.url.split("?")[1] ?? "");
try {
if (req.method == "GET") {
if ( req.url === "/") return toText(res, banner());
if ( req.url === "/health" ) {
const messages = await getSingleMetric("substreams_sink_data_message")
if ( messages ) return toText(res, "OK");
return toText(res, "no messages received yet", 503);
}
}
// throw new Error(`invalid request`);
} catch (err: any) {
res.statusCode = 400;
return res.end(err.message);
}
});
}
/health
endpoint which returns"OK"
status 200 (or204
really)Reference
https://docs.railway.app/deploy/healthchecks
""" First, make sure your webserver has an endpoint (e.g. /health) that will return a response with HTTP status code 200 when your application is live and ready. If your application needs to do some initialization on startup (running database migrations, populating cache, etc.), it's a good idea to return a non-200 status code from your endpoint until the initialization completes. """
Example