Build HTTP server for admin API#14
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a Node.js HTTP server/CLI wrapper for the existing AdminHandler, turning the admin API into a runnable service and documenting the endpoints for Issue #13 (Phase 1).
Changes:
- Add
startServer()HTTP server that matches routes, parses JSON, and forwards requests intoAdminHandler. - Add a
cli.tsentrypoint that starts the server usingPORT/HOSTenv vars. - Expand
src/admin-ui/README.mdwith endpoint docs and startup instructions.
Standards (repo standards + smell baseline)
- Duplicated Code (judgement call):
server.tsreimplements route matching/body parsing even thoughhandler.tsalready contains a testedmatchRouteandnodeHttpAdapter, increasing drift risk. - Operational baseline: default bind host of
localhostis likely surprising for a deployable service (often should bind to all interfaces by default).
Spec (Issue #13 acceptance criteria)
- Meets: port defaults to 3000 and is configurable via
PORT; 5 endpoints are represented; CLI path matches requirement; README exists with endpoint list. - Falls short / incorrect: malformed JSON currently becomes a 500 (PR description calls out 400 handling); README request examples do not match the actual domain types (
ProvisioningTarget,DesiredStateSnapshot).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 9 comments.
| File | Description |
|---|---|
| src/admin-ui/server.ts | Adds HTTP server wrapper and request bridging into AdminHandler. |
| src/admin-ui/cli.ts | Adds CLI entrypoint to start the admin HTTP server. |
| src/admin-ui/README.md | Documents server startup and the 5 REST endpoints. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+100
to
+104
| } catch (error) { | ||
| console.error('Handler error:', error); | ||
| res.writeHead(500, {'Content-Type': 'application/json'}); | ||
| res.end(JSON.stringify({error: 'Internal server error'})); | ||
| } |
Comment on lines
+49
to
+63
| let data = ''; | ||
| req.on('data', (chunk) => { | ||
| data += chunk.toString(); | ||
| }); | ||
| req.on('end', () => { | ||
| if (!data) { | ||
| resolve(undefined); | ||
| return; | ||
| } | ||
| try { | ||
| resolve(JSON.parse(data)); | ||
| } catch (e) { | ||
| reject(new Error('Invalid JSON')); | ||
| } | ||
| }); |
Comment on lines
+14
to
+18
| function matchRoute(path: string, pattern: string): Record<string, string>|null { | ||
| const patternSegments = pattern.split('/'); | ||
| const pathSegments = path.split('/'); | ||
| if (patternSegments.length !== pathSegments.length) return null; | ||
|
|
Comment on lines
+75
to
+77
| const method = (req.method || 'GET') as HttpMethod; | ||
| const pathname = new URL(req.url || '/', `http://${req.headers.host}`).pathname; | ||
|
|
Comment on lines
+4
to
+5
| const port = parseInt(process.env.PORT || '3000', 10); | ||
| const host = process.env.HOST || 'localhost'; |
Comment on lines
+108
to
+110
| const host = config.host || 'localhost'; | ||
| server.listen(config.port, host, () => { | ||
| console.log(`Server listening on http://${host}:${config.port}`); |
Comment on lines
+33
to
+38
| "target": { | ||
| "createDatabase": true, | ||
| "createIngress": true, | ||
| "createDns": true, | ||
| "createSecrets": true | ||
| } |
Comment on lines
+62
to
+65
| "snapshot": { | ||
| "keycloakConfig": {...}, | ||
| "authProviders": [...] | ||
| } |
Comment on lines
+68
to
+72
| export async function startServer(config: ServerConfig): Promise<Server> { | ||
| const repository = new InMemoryDeploymentRepository(); | ||
| const core = new CoreService(repository); | ||
| const handler = new AdminHandler(core); | ||
|
|
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: #13
Summary
Builds a real Node.js HTTP server that bridges the AdminHandler into a deployable service. This is Phase 1 of the implementation roadmap.
Changes
Architecture
The server uses Node's built-in http module with:
Testing
Verified all 5 endpoints manually with curl:
All responses return correct status codes (201 Created, 200 OK) and valid JSON.