initial
This commit is contained in:
59
ts/server/classes.viewserver.ts
Normal file
59
ts/server/classes.viewserver.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
1
ts/server/index.ts
Normal file
1
ts/server/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './classes.viewserver.js';
|
||||
Reference in New Issue
Block a user