feat: add health check endpoint - #197
Open
Arnish-val wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a lightweight liveness/readiness endpoint to the Express backend so deployments behind proxies/CI can probe server availability without hitting data-heavy routes.
Changes:
- Added
GET /api/healthreturning{ status: "ok", version: <string> }. - Added a Vitest integration test that starts the app and probes
/api/health.
Show a summary per file
| File | Description |
|---|---|
src/server.ts |
Adds the /api/health route to the Express app. |
src/__tests__/server.test.ts |
Adds an integration test that starts a local server and validates the health response. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 3
- Review effort level: Low
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Review details
Suppressed comments (3)
src/server.ts:65
- The new /api/health handler is the only route here without the existing try/catch + JSON 500 error pattern used by the other endpoints. For consistency (and to avoid any unexpected unhandled errors), wrap the handler body in try/catch and return a JSON error on failure.
// API: Health check
app.get("/api/health", (_req, res) => {
res.status(200).json({
status: "ok",
version: appVersion,
});
});
src/server.ts:57
- These newly added lines contain stray carriage-return characters (mixed CRLF/LF), which can cause noisy diffs and tooling issues. Please normalize line endings in this block to match the rest of the file (LF).
// Cache version once when the app is created (avoid per-request I/O)
let appVersion = process.env.npm_package_version;
if (!appVersion) {
try {
appVersion = (require("../package.json") as { version?: string }).version;
src/tests/server.test.ts:44
- If server.address() is missing/unexpected, the test throws before entering the try/finally and the server is never closed. Move the address validation inside the try block so the server is always closed in finally.
const address = server.address();
if (!address || typeof address === "string") {
throw new Error("Test server did not start correctly");
}
- Files reviewed: 2/2 changed files
- Comments generated: 0 new
- Review effort level: Lite
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #193
Summary
GET /api/healthendpoint.okstatus and version string.Testing
GET /api/healthlocally.npm test.