From abe65d5fe35ff69230001bb9ed6ad5cd84ae68ae Mon Sep 17 00:00:00 2001 From: Tran Minh Quy Date: Tue, 26 Nov 2024 15:03:29 +0700 Subject: [PATCH] diagramsio: add `/health` Add `/health` for diagrams.io for supporting health check --- diagrams.net/src/index.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/diagrams.net/src/index.js b/diagrams.net/src/index.js index 673d6b778..6a5653f88 100644 --- a/diagrams.net/src/index.js +++ b/diagrams.net/src/index.js @@ -14,6 +14,14 @@ import { SyntaxError, TimeoutError, Worker } from './worker.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') { + let sample = `` + await worker.convert(new Task(sample, 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 diagrams.net 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