feat(ops-server): implement TypedRouter integration and modular handler classes

This commit is contained in:
Juergen Kunz
2025-06-08 07:04:35 +00:00
parent ab19130904
commit 61778bdba8
10 changed files with 1188 additions and 14 deletions

View File

@ -1,13 +1,27 @@
import type DcRouter from '../classes.dcrouter.js';
import * as plugins from '../plugins.js';
import * as paths from '../paths.js';
import * as handlers from './handlers/index.js';
export class OpsServer {
public dcRouterRef: DcRouter;
public server: plugins.typedserver.utilityservers.UtilityWebsiteServer;
// TypedRouter for OpsServer-specific handlers
public typedrouter = new plugins.typedrequest.TypedRouter();
// Handler instances
private adminHandler: handlers.AdminHandler;
private configHandler: handlers.ConfigHandler;
private logsHandler: handlers.LogsHandler;
private securityHandler: handlers.SecurityHandler;
private statsHandler: handlers.StatsHandler;
constructor(dcRouterRefArg: DcRouter) {
this.dcRouterRef = dcRouterRefArg;
// Add our typedrouter to the dcRouter's main typedrouter
this.dcRouterRef.typedrouter.addTypedRouter(this.typedrouter);
}
public async start() {
@ -16,9 +30,34 @@ export class OpsServer {
feedMetadata: null,
serveDir: paths.distServe,
});
// The server has a built-in typedrouter at /typedrequest
// Add the main dcRouter typedrouter to the server's typedrouter
this.server.typedrouter.addTypedRouter(this.dcRouterRef.typedrouter);
// Set up handlers
this.setupHandlers();
await this.server.start(3000);
}
/**
* Set up all TypedRequest handlers
*/
private setupHandlers(): void {
// Instantiate all handlers - they self-register with the typedrouter
this.adminHandler = new handlers.AdminHandler(this);
this.configHandler = new handlers.ConfigHandler(this);
this.logsHandler = new handlers.LogsHandler(this);
this.securityHandler = new handlers.SecurityHandler(this);
this.statsHandler = new handlers.StatsHandler(this);
console.log('✅ OpsServer TypedRequest handlers initialized');
}
public async stop() {}
public async stop() {
if (this.server) {
await this.server.stop();
}
}
}