Skip to content

Build HTTP server for admin API#14

Merged
LahkLeKey merged 1 commit into
mainfrom
feature/http-server
Jul 12, 2026
Merged

Build HTTP server for admin API#14
LahkLeKey merged 1 commit into
mainfrom
feature/http-server

Conversation

@LahkLeKey

Copy link
Copy Markdown
Owner

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

  • src/admin-ui/server.ts (71 lines) — HTTP server factory with route matching and request/response bridging
  • src/admin-ui/cli.ts (14 lines) — CLI entry point that starts the server with PORT/HOST env vars
  • src/admin-ui/README.md — Complete API documentation and startup instructions

Architecture

The server uses Node's built-in http module with:

  • Route pattern matching (supports :id path parameters)
  • JSON serialization/deserialization
  • Error handling (400/404/500 responses)
  • Async request body parsing

Testing

Verified all 5 endpoints manually with curl:

# Start server
PORT=3001 node --experimental-transform-types src/admin-ui/cli.ts

# Test endpoints
curl -X POST http://localhost:3001/deployments -H 'Content-Type: application/json' -d '{...}'
curl http://localhost:3001/deployments
curl http://localhost:3001/deployments/$id
curl -X PUT http://localhost:3001/deployments/$id/status -H 'Content-Type: application/json' -d '{...}'
curl -X POST http://localhost:3001/deployments/$id/versions -H 'Content-Type: application/json' -d '{...}'

All responses return correct status codes (201 Created, 200 OK) and valid JSON.

Copilot AI review requested due to automatic review settings July 12, 2026 01:37
@LahkLeKey LahkLeKey self-assigned this Jul 12, 2026
@LahkLeKey
LahkLeKey merged commit 417e789 into main Jul 12, 2026
@LahkLeKey
LahkLeKey deleted the feature/http-server branch July 12, 2026 01:37

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 into AdminHandler.
  • Add a cli.ts entrypoint that starts the server using PORT/HOST env vars.
  • Expand src/admin-ui/README.md with endpoint docs and startup instructions.

Standards (repo standards + smell baseline)

  • Duplicated Code (judgement call): server.ts reimplements route matching/body parsing even though handler.ts already contains a tested matchRoute and nodeHttpAdapter, increasing drift risk.
  • Operational baseline: default bind host of localhost is 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 thread src/admin-ui/server.ts
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 thread src/admin-ui/server.ts
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 thread src/admin-ui/server.ts
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 thread src/admin-ui/server.ts
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 thread src/admin-ui/cli.ts
Comment on lines +4 to +5
const port = parseInt(process.env.PORT || '3000', 10);
const host = process.env.HOST || 'localhost';
Comment thread src/admin-ui/server.ts
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 thread src/admin-ui/README.md
Comment on lines +33 to +38
"target": {
"createDatabase": true,
"createIngress": true,
"createDns": true,
"createSecrets": true
}
Comment thread src/admin-ui/README.md
Comment on lines +62 to +65
"snapshot": {
"keycloakConfig": {...},
"authProviders": [...]
}
Comment thread src/admin-ui/server.ts
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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants