Add healthcheck
This commit is contained in:
11
Dockerfile
11
Dockerfile
@@ -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"]
|
||||||
|
|||||||
@@ -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}`
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user