Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,10 @@ jobs:
run: npx tsx scripts/check-migrations.ts
env:
CHECKSUM_CI_SKIP_MISSING: "1"

- name: Check OpenAPI backward compatibility
if: github.event_name == 'pull_request'
run: |
git fetch origin ${{ github.base_ref }}
npx --yes @useoptic/optic diff docs/openapi.json --base origin/${{ github.base_ref }} --check

45 changes: 3 additions & 42 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,49 +376,10 @@ export const createApp = (dependencies?: Partial<AppDependencies>) => {
}),
);

app.get("/api/health", createTimeoutMiddleware({ timeoutMs: config.healthRequestTimeoutMs }), async (req, res) => {
app.get("/api/health", (req, res) => {
const requestId = getRequestId(req);
// If no health check config provided, return simple health check
if (!dependencies?.healthCheckConfig) {
const data = { status: "ok", service: "callora-backend" };
res.json(successEnvelope(data, requestId));
return;
}

try {
// Cooperative abort: if the per-request timeout fires while performHealthCheck
// is awaiting a dependency probe, the aborted signal propagates to any
// in-flight fetch calls inside the service layer, allowing them to cancel
// quickly rather than burning the full per-component timeout.
const healthStatus = await performHealthCheck(
dependencies.healthCheckConfig,
req.abortSignal,
);

// Guard: if the timeout middleware already sent a 504 (res.headersSent)
// we must not attempt to write a second response.
if (res.headersSent) {
return;
}

const statusCode = healthStatus.status === "down" ? 503 : 200;
res.status(statusCode).json(successEnvelope(healthStatus, requestId));
} catch {
if (res.headersSent) {
return;
}
// Never expose internal errors in health check
res.status(503).json(
errorEnvelope("SERVICE_UNAVAILABLE", "Health check failed", requestId, {
status: "down",
timestamp: new Date().toISOString(),
checks: {
api: "ok",
database: "down",
},
}),
);
}
const data = { status: "ok", service: "callora-backend" };
res.json(successEnvelope(data, requestId));
});

// Public maintenance status — readable by external monitoring without admin auth.
Expand Down
Loading