From 42d27e96d7b9c3e2544e533ce527b45154ef70ab Mon Sep 17 00:00:00 2001 From: Charles Date: Fri, 21 Sep 2018 17:04:32 +0200 Subject: [PATCH] Add a GET /status 200 Add a healthcheck in docker conf --- Dockerfile | 4 ++++ index.js | 24 +++++++++++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index d67ff74..6498474 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,4 +8,8 @@ ENV TILE_SET_CACHE 128 ENV TILE_SET_PATH /app/data ENV MAX_POST_SIZE 700kb +EXPOSE 3000 + +HEALTHCHECK CMD curl --fail http://localhost:3000/status || exit 1 + CMD ["yarn", "run", "start"] diff --git a/index.js b/index.js index 52e4c81..10ac732 100644 --- a/index.js +++ b/index.js @@ -53,13 +53,23 @@ async function handleGET(req, res) { return result; } +async function handleGETStatus(req, res) { + return send(res, 200); +} + module.exports = async (req, res) => { - switch (req.method) { - case "POST": - return handlePOST(req, res); - case "GET": - return handleGET(req, res); - default: - return send(res, 405, { error: "Only GET or POST allowed" }); + if (req.method == "GET" && req.url == "/status") { + return handleGETStatus(req, res); + } + else + { + switch (req.method) { + case "POST": + return handlePOST(req, res); + case "GET": + return handleGET(req, res); + default: + return send(res, 405, { error: "Only GET or POST allowed" }); + } } };