Skip to content

Commit

Permalink
Adding a health check that can be used to determine if the worker is …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
bra1nDump committed Jun 17, 2023
1 parent c8f3e4e commit 285498c
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions mermaid/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 285498c

Please sign in to comment.