type ResponsePayload,
type UIServerConfiguration
} from '../../types/index.js'
+import { logger } from '../../utils/index.js'
+
+const moduleName = 'AbstractUIServer'
export abstract class AbstractUIServer {
public readonly chargingStations: Map<string, ChargingStationData>
}
protected startHttpServer (): void {
+ this.httpServer.on('error', error => {
+ logger.error(
+ `${this.logPrefix(moduleName, 'start.httpServer.on.error')} HTTP server error:`,
+ error
+ )
+ })
if (!this.httpServer.listening) {
this.httpServer.listen(this.uiServerConfiguration.options)
}
private stopHttpServer (): void {
if (this.httpServer.listening) {
this.httpServer.close()
+ this.httpServer.removeAllListeners()
}
}
}
})
this.httpServer.on('upgrade', (req: IncomingMessage, socket: Duplex, head: Buffer): void => {
+ const onSocketError = (error: Error): void => {
+ logger.error(
+ `${this.logPrefix(
+ moduleName,
+ 'start.httpServer.on.upgrade'
+ )} Socket error at connection upgrade event handling:`,
+ error
+ )
+ }
+ socket.on('error', onSocketError)
this.authenticate(req, err => {
if (err != null) {
socket.write(`HTTP/1.1 ${StatusCodes.UNAUTHORIZED} Unauthorized\r\n\r\n`)
`${this.logPrefix(
moduleName,
'start.httpServer.on.upgrade'
- )} Error at handling connection upgrade:`,
+ )} Error at connection upgrade event handling:`,
error
)
}
})
+ socket.removeListener('error', onSocketError)
})
this.startHttpServer()
}