Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,5 @@ EXPOSE 80
USER node:node

ENTRYPOINT ["/usr/src/app/docker-entrypoint.sh"]

HEALTHCHECK CMD node /usr/src/app/src/healthcheck.js
1 change: 1 addition & 0 deletions Dockerfile_light
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ COPY / /usr/src/app
RUN cd /usr/src/app && npm install --omit=dev
RUN ["chmod", "+x", "/usr/src/app/docker-entrypoint.sh"]
USER node:node
HEALTHCHECK CMD node /usr/src/app/src/healthcheck.js
18 changes: 18 additions & 0 deletions src/healthcheck.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as http from 'http';
var options = {
timeout: 2000,
};
var url = "http://localhost:80/health";
var request = http.request(url, options, (res) => {
console.log(`STATUS: ${res.statusCode}`);
if (res.statusCode == 200) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (res.statusCode == 200) {
if (res.statusCode === 200) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type of the response StatusCode is a number. IMO, === is not needed for comparing that number with 200.

process.exit(0);
} else {
process.exit(1);
}
});
request.on("error", function (err) {
console.log("ERROR");
process.exit(1);
});
request.end();