feat(backend): security, health checks, graceful shutdown, and contribution guide - #505
Conversation
…ceful shutdown, and contributing guide - feat(security): integrate helmet middleware with CSP configured for API-only responses - feat(health): add GET /api/health/deep endpoint with per-component status checks - Checks SQLite database reachability and read/write capability - Verifies Soroban RPC endpoint accessibility - Validates CONTRACT_ID configuration - Returns 503 if any critical component is down - feat(shutdown): implement graceful shutdown handling for SIGTERM/SIGINT signals - 10-second grace period for in-flight requests to complete - New requests receive 503 Service Unavailable during shutdown - Explicit database connection closure before exit - docs(contributing): expand CONTRIBUTING.md with detailed backend setup section - Node.js and npm prerequisites - Environment variable configuration guide - Development server startup instructions - Test running (watch mode and coverage) - Database seeding and troubleshooting guide - deps: add helmet package for security headers - test(security): add comprehensive tests for helmet headers and deep health endpoint
|
@williamedvard is attempting to deploy a commit to the ritik4ever's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@williamedvard Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughAdds ChangesBackend Security and Ops
CONTRIBUTING.md Backend Docs
Sequence Diagram(s)sequenceDiagram
participant Client
participant HealthDeepRoute as GET /api/health/deep
participant checkDbHealth
participant SorobanRPC as Soroban RPC (getHealth)
Client->>HealthDeepRoute: GET /api/health/deep
HealthDeepRoute->>checkDbHealth: check DB reachability
checkDbHealth-->>HealthDeepRoute: {status, reachable, error?}
HealthDeepRoute->>SorobanRPC: fetch getHealth (5s timeout)
SorobanRPC-->>HealthDeepRoute: ok or throws
HealthDeepRoute-->>Client: 200 {overall, components: {db, soroban, contract}} or 503
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install failed: one or more packages not found in the registry. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Warning |
| import "dotenv/config"; | ||
| import express, { Request, Response } from "express"; | ||
| import helmet from "helmet"; | ||
| import http, { Server } from "http"; |
Summary
Implemented backend security hardening with helmet middleware, comprehensive health checks, graceful shutdown handling, and expanded contribution documentation.
Issues Resolved
Closes #224
Closes #226
Closes #227
Closes #228
Changes
Issue #224: Add helmet security headers to Express app
default-src 'none'for API-only responsesIssue #226: Expand CONTRIBUTING.md with backend setup
Issue #227: Add GET /api/health/deep endpoint
overall: 'up' or 'down'components: Per-component status with detailstimestamp: ISO 8601 timestampuptimeSeconds: Server uptimeIssue #228: Add graceful shutdown to Express server
Technical Details
Middleware Order
Health Check Hierarchy
/api/health: Basic SQLite reachability/api/health/deep: Full dependency verificationDatabase Update
checkDbHealth()to include error details for deep health checksTesting
Acceptance Criteria
default-src 'none'for APISummary by CodeRabbit
New Features
Bug Fixes
Documentation