Add healthcheck

This commit is contained in:
2026-01-15 09:41:02 +01:00
parent 38e5654341
commit 58b8cf3bdc
2 changed files with 14 additions and 2 deletions

View File

@@ -1,8 +1,15 @@
FROM node:lts-alpine FROM node:lts-alpine
USER node USER node
WORKDIR /app WORKDIR /app
ENV NODE_ENV production ENV NODE_ENV=production
ENV TZ Europe/Warsaw ENV TZ=Europe/Warsaw
COPY --chown=node:node index.mjs ./ COPY --chown=node:node index.mjs ./
EXPOSE 3000 EXPOSE 3000
CMD ["node", "./index.mjs"] CMD ["node", "./index.mjs"]
HEALTHCHECK \
--interval=10s \
--timeout=5s \
--start-period=3s \
--retries=3 \
CMD ["wget", "http://localhost/health", "-O", "/dev/null", "-q"]

View File

@@ -15,6 +15,11 @@ const server = createServer((req, res) => {
const host = req.headers['x-forwarded-host']; const host = req.headers['x-forwarded-host'];
const endpoint = `${req.method} ${req.url}`; const endpoint = `${req.method} ${req.url}`;
if (endpoint === 'GET /health') {
res.statusCode = 200;
return res.end('OK\n');
}
console.log( console.log(
`[${dateText}] ${scannerIP} (${userAgent}) targeted ${host} on ${endpoint}` `[${dateText}] ${scannerIP} (${userAgent}) targeted ${host} on ${endpoint}`
); );