- Update ApiService baseUrl to include /typedrequest path that TypedServer expects - Add noCache option to ViewServer to prevent client caching issues during development - Update @api.global/typedserver to v8.3.0 which includes the noCache feature
61 lines
1.6 KiB
TypeScript
61 lines
1.6 KiB
TypeScript
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,
|
|
noCache: 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;
|
|
}
|
|
}
|
|
}
|