-
Notifications
You must be signed in to change notification settings - Fork 464
add-a-simple-health-endpoint-to-the-api: add GET /health endpoint #617
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
happyforever006
wants to merge
1
commit into
breaking-brake:main
Choose a base branch
from
happyforever006:feat/add-a-simple-health-endpoint-to-the-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| /** | ||
| * Claude Code Workflow Studio - Health Server Service | ||
| * | ||
| * Provides a simple HTTP server exposing a /health endpoint for monitoring | ||
| * and integration testing. The server starts on extension activation and | ||
| * shuts down on deactivation. | ||
| * | ||
| * Endpoint: | ||
| * GET /health → 200 OK | ||
| * { | ||
| * "status": "ok", | ||
| * "name": "cc-wf-studio", | ||
| * "version": "<extension-version>", | ||
| * "timestamp": "<ISO-8601>" | ||
| * } | ||
| * | ||
| * Default port: 3456 (configurable via constructor) | ||
| */ | ||
|
|
||
| import * as http from 'node:http'; | ||
| import { log } from '../extension'; | ||
|
|
||
| /** | ||
| * Response body returned by the /health endpoint | ||
| */ | ||
| export interface HealthResponse { | ||
| /** Overall health status */ | ||
| status: 'ok'; | ||
| /** Extension name */ | ||
| name: string; | ||
| /** Extension version */ | ||
| version: string; | ||
| /** ISO 8601 timestamp of the response */ | ||
| timestamp: string; | ||
| } | ||
|
|
||
| /** | ||
| * Health Server Service | ||
| * | ||
| * Starts a lightweight HTTP server that exposes a /health endpoint. | ||
| * Intended for use by monitoring tools, CI pipelines, and integration tests. | ||
| */ | ||
| export class HealthServerService { | ||
| private server: http.Server | null = null; | ||
| private readonly port: number; | ||
| private readonly name: string; | ||
| private readonly version: string; | ||
|
|
||
| /** | ||
| * @param name - Extension name (from package.json `name` field) | ||
| * @param version - Extension version (from package.json `version` field) | ||
| * @param port - Port to listen on (default: 3456) | ||
| */ | ||
| constructor(name: string, version: string, port = 3456) { | ||
| this.name = name; | ||
| this.version = version; | ||
| this.port = port; | ||
| } | ||
|
|
||
| /** | ||
| * Starts the health HTTP server. | ||
| * | ||
| * Resolves when the server is listening. | ||
| * Rejects if the port is already in use or the server fails to start. | ||
| */ | ||
| start(): Promise<void> { | ||
| return new Promise((resolve, reject) => { | ||
| this.server = http.createServer((req, res) => { | ||
| this.handleRequest(req, res); | ||
| }); | ||
|
|
||
| this.server.on('error', (err) => { | ||
| log('ERROR', 'Health server error', { error: err.message }); | ||
| reject(err); | ||
| }); | ||
|
|
||
| this.server.listen(this.port, '127.0.0.1', () => { | ||
| log('INFO', `Health server listening on http://127.0.0.1:${this.port}/health`); | ||
| resolve(); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Stops the health HTTP server. | ||
| * | ||
| * Resolves when the server has closed all connections. | ||
| */ | ||
| stop(): Promise<void> { | ||
| return new Promise((resolve) => { | ||
| if (!this.server) { | ||
| resolve(); | ||
| return; | ||
| } | ||
|
|
||
| this.server.close((err) => { | ||
| if (err) { | ||
| log('WARN', 'Health server stop error', { error: err.message }); | ||
| } else { | ||
| log('INFO', 'Health server stopped'); | ||
| } | ||
| this.server = null; | ||
| resolve(); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Routes an incoming HTTP request. | ||
| * | ||
| * Only GET /health is handled; all other requests receive 404. | ||
| */ | ||
| private handleRequest(req: http.IncomingMessage, res: http.ServerResponse): void { | ||
| if (req.method === 'GET' && req.url === '/health') { | ||
| this.handleHealth(res); | ||
| } else { | ||
| res.writeHead(404, { 'Content-Type': 'application/json' }); | ||
| res.end(JSON.stringify({ error: 'Not Found' })); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Responds to GET /health with a 200 OK and a HealthResponse JSON body. | ||
| */ | ||
| private handleHealth(res: http.ServerResponse): void { | ||
| const body: HealthResponse = { | ||
| status: 'ok', | ||
| name: this.name, | ||
| version: this.version, | ||
| timestamp: new Date().toISOString(), | ||
| }; | ||
|
|
||
| const json = JSON.stringify(body); | ||
| res.writeHead(200, { | ||
| 'Content-Type': 'application/json', | ||
| 'Content-Length': Buffer.byteLength(json), | ||
| }); | ||
| res.end(json); | ||
|
|
||
| log('INFO', 'Health check request served'); | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Async cleanup may not complete before extension fully deactivates.
The
deactivate()function returnsvoidbuthealthServer?.stop()is async. VS Code supports returningThenable<void>fromdeactivate()to allow proper async cleanup. Currently:outputChannel?.dispose()may execute before the server finishes stoppingConsider returning the promise to ensure clean shutdown.
🔧 Suggested fix for proper async cleanup
🤖 Prompt for AI Agents