From 285498ce77bc1e43b1cfcbe7686be18dfe62c028 Mon Sep 17 00:00:00 2001 From: Kirill Dubovitskiy Date: Sat, 17 Jun 2023 16:01:34 -0700 Subject: [PATCH] Adding a health check that can be used to determine if the worker is healthy (#1572) * Adding a health check that can be used to determine if the worker is healthy. I am using fly.io to deploy and it has health checks, but you can't specify a payload to send, has to be a simple request without any parameters * Address comments * Update index.js --- mermaid/src/index.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mermaid/src/index.js b/mermaid/src/index.js index bb872febc..5279f6ef5 100644 --- a/mermaid/src/index.js +++ b/mermaid/src/index.js @@ -15,6 +15,14 @@ import { create } from './browser-instance.js' const worker = new Worker(browser) const server = new http.Server( micro.serve(async (req, res) => { + // Add a /health route that renders a sample diagram by calling the worker + if (req.url === '/health') { + await worker.convert(new Task('graph TD\nA-->B', false), new URLSearchParams()) + + // We don't actually care about the output, we just want to make sure the worker is up and running + return micro.send(res, 200, 'OK') + } + // TODO: add a /_status route (return mermaid version) // TODO: read the diagram source as plain text const url = new URL(req.url, 'http://localhost') // create a URL object. The base is not important here