Skip to content

Commit

Permalink
feat: add health-check (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtPooki authored Oct 23, 2023
1 parent 732c655 commit 6f371e4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ WORKDIR /app
COPY . .
RUN npm ci --quiet
RUN npm run build

HEALTHCHECK --interval=12s --timeout=12s --start-period=10s CMD npm run healthcheck

CMD [ "npm", "start" ]
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"build": "aegir build --bundle false",
"start": "node dist/src/index.js",
"start:dev": "npm run build && node dist/src/index.js",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"healthcheck": "node dist/src/healthcheck.js"
},
"type": "module",
"repository": {
Expand Down
9 changes: 9 additions & 0 deletions src/healthcheck.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env node
/**
* This healthcheck script is used to check if the server is running and healthy.
*/
const rootReq = await fetch(`http://localhost:${process.env.PORT ?? 8080}`, { method: 'GET' })
const status = rootReq.status
// eslint-disable-next-line no-console
console.log(`Healthcheck status: ${status}`)
process.exit(status === 200 ? 0 : 1)

0 comments on commit 6f371e4

Please sign in to comment.