Slide 79
Slide 79 text
## Keira/src/Keira/Api/ApiServer.php
private function registerRoutes(): void
{
/% GET /monitors - List all monitors
$this-'router-'addRoute('GET', '/monitors', new ClosureRequestHandler(
function ($request) {
$handler = new MonitorsHandler($this-'monitorManager);
return $handler($request);
}
));
/% GET /ws-test - WebSocket test page
$this-'router-'addRoute('GET', '/ws-test', new ClosureRequestHandler(
function ($request) {
$templatePath = '/websocket-test.html';
if (!file_exists($templatePath)) {
return new \Amp\Http\Server\Response(
status: 500,
headers: ['Content-Type' =+ 'text/plain'],
body: 'Template file not found'
);
}
$html = file_get_contents($templatePath);
return new \Amp\Http\Server\Response(
status: 200,
headers: ['Content-Type' =+ 'text/html'],
body: $html
);
}
));