This commit is contained in:
2026-01-23 22:15:51 +00:00
commit 74d24cf8b9
44 changed files with 15483 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
import * as plugins from '../plugins.js';
import type { TsView } from '../tsview.classes.tsview.js';
import { registerS3Handlers } from '../api/handlers.s3.js';
import { registerMongoHandlers } from '../api/handlers.mongodb.js';
import { files as bundledUiFiles } from '../bundled_ui.js';
/**
* Web server for TsView that serves the bundled UI and API endpoints.
*/
export class ViewServer {
private tsview: TsView;
private port: number;
private typedServer: plugins.typedserver.TypedServer | null = null;
public typedrouter: plugins.typedrequest.TypedRouter;
constructor(tsview: TsView, port: number) {
this.tsview = tsview;
this.port = port;
this.typedrouter = new plugins.typedrequest.TypedRouter();
}
/**
* Start the server
*/
public async start(): Promise<void> {
// Register API handlers
if (this.tsview.config.hasS3()) {
await registerS3Handlers(this.typedrouter, this.tsview);
}
if (this.tsview.config.hasMongo()) {
await registerMongoHandlers(this.typedrouter, this.tsview);
}
// Create typed server with bundled content
this.typedServer = new plugins.typedserver.TypedServer({
cors: true,
port: this.port,
bundledContent: bundledUiFiles,
spaFallback: true,
});
// Add the router
this.typedServer.typedrouter.addTypedRouter(this.typedrouter);
// Start server
await this.typedServer.start();
}
/**
* Stop the server
*/
public async stop(): Promise<void> {
if (this.typedServer) {
await this.typedServer.stop();
this.typedServer = null;
}
}
}