Added Json targetPort for K8S
MODIFY
src/assets/schemas/configuration/configuration.json
src/assets/schemas/configuration/configuration.json
"properties": {
"baseSecureUrl": {
"type": "string"
+ },
+ "targetPort": {
+ "type": "integer"
}
},
"required": [

MODIFY
src/client/ocpp/json/JsonRestChargingStationClient.ts
src/client/ocpp/json/JsonRestChargingStationClient.ts
@@ -5,6 +5,7 @@ import { ServerAction, WSServerProtocol } from '../../../types/Server';
import BackendError from '../../../exception/BackendError';
import ChargingStationClient from '../ChargingStationClient';
+import Configuration from '../../../utils/Configuration';
import Logging from '../../../utils/Logging';
import LoggingHelper from '../../../utils/LoggingHelper';
import Utils from '../../../utils/Utils';
@@ -14,6 +15,7 @@ import { WSClientOptions } from '../../../types/WebSocket';
const MODULE_NAME = 'JsonRestChargingStationClient';
export default class JsonRestChargingStationClient extends ChargingStationClient {
+ private jsonEndoint = Configuration.getJsonEndpointConfig();
private serverURL: string;
private chargingStation: ChargingStation;
private requests: { [messageUID: string]: { resolve?: (result: Record<string, unknown> | string) => void; reject?: (error: Record<string, unknown>) => void; command: Command } };
@@ -26,9 +28,9 @@ export default class JsonRestChargingStationClient extends ChargingStationClient
// Get URL
let jsonServerURL: string;
// Check K8s
- if (process.env.K8S && process.env.OCPPJ_TARGET_PORT && chargingStation.cloudHostIP) {
+ if (process.env.K8S && this.jsonEndoint.targetPort && chargingStation.cloudHostIP) {
// Use K8s internal IP, always in ws
- jsonServerURL = `ws://${chargingStation.cloudHostIP}:${process.env.OCPPJ_TARGET_PORT}`;
+ jsonServerURL = `ws://${chargingStation.cloudHostIP}:${this.jsonEndoint.targetPort}`;
} else {
jsonServerURL = chargingStation.chargingStationURL;
if (!jsonServerURL) {

MODIFY
src/types/configuration/JsonEndpointConfiguration.ts
src/types/configuration/JsonEndpointConfiguration.ts
export default interface JsonEndpointConfiguration {
baseSecureUrl?: string;
+ targetPort?: number;
}

MODIFY
src/utils/Configuration.ts
src/utils/Configuration.ts
@@ -151,6 +151,9 @@ export default class Configuration {
public static getJsonEndpointConfig(): JsonEndpointConfiguration {
const jsonEndpoint = Configuration.getConfig().JsonEndpoint;
if (!Configuration.isUndefined('JsonEndpoint', jsonEndpoint)) {
+ if (Configuration.isUndefined('JsonEndpoint.targetPort', jsonEndpoint.targetPort)) {
+ jsonEndpoint.targetPort = 80;
+ }
return jsonEndpoint;
}
}

Added Json targetPort for K8S