import { StatusCodes } from 'http-status-codes';
+import { AbstractUIServer } from './AbstractUIServer';
+import { UIServerUtils } from './UIServerUtils';
import BaseError from '../../exception/BaseError';
import type { UIServerConfiguration } from '../../types/ConfigurationData';
import {
- ProcedureName,
- Protocol,
- ProtocolRequest,
- ProtocolResponse,
- ProtocolVersion,
- RequestPayload,
+ type ProcedureName,
+ type Protocol,
+ type ProtocolRequest,
+ type ProtocolResponse,
+ type ProtocolVersion,
+ type RequestPayload,
ResponseStatus,
} from '../../types/UIProtocol';
import logger from '../../utils/Logger';
import Utils from '../../utils/Utils';
-import { AbstractUIServer } from './AbstractUIServer';
-import { UIServiceUtils } from './ui-services/UIServiceUtils';
const moduleName = 'UIHttpServer';
public start(): void {
this.httpServer.on('request', this.requestListener.bind(this) as RequestListener);
- if (this.httpServer.listening === false) {
- this.httpServer.listen(this.uiServerConfiguration.options);
- }
+ this.startHttpServer();
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const uuid = Utils.generateUUID();
this.responseHandlers.set(uuid, res);
try {
- if (UIServiceUtils.isProtocolAndVersionSupported(protocol, version) === false) {
- throw new BaseError(`Unsupported UI protocol version: '/${protocol}/${version}'`);
+ const fullProtocol = `${protocol}${version}`;
+ if (UIServerUtils.isProtocolAndVersionSupported(fullProtocol) === false) {
+ throw new BaseError(`Unsupported UI protocol version: '${fullProtocol}'`);
}
this.registerProtocolVersionUIService(version);
req.on('error', (error) => {
const body = JSON.parse(Buffer.concat(bodyBuffer).toString()) as RequestPayload;
this.uiServices
.get(version)
- .requestHandler(this.buildProtocolRequest(uuid, procedureName, body ?? {}))
+ ?.requestHandler(this.buildProtocolRequest(uuid, procedureName, body ?? {}))
.catch(() => {
/* Error caught by AbstractUIService */
});