import {GatewayConfig} from "../config/GatewayConfig";
import {StcHttpRequestObj} from "../model/StcHttpRequestObj";
import {MsNodeType} from "../enums/MsNodeType";
import {RouteType} from "../enums/RouteType";

/**
 * 缩减版的 SideCar
 */
class SideCar {

    buildHostUrl(serviceClientConfig: GatewayConfig, sid: string, version: string, requestObj: StcHttpRequestObj): string {
        requestObj.fromNode = MsNodeType.CLIENT_JS;
        requestObj.toNode = MsNodeType.GATEWAY;
        if (serviceClientConfig.routeType == RouteType.GATE_WAY) { //A.走网关
            return serviceClientConfig.hostAddress
        } else {
            throw Error(`Unknown RouteType [ ${serviceClientConfig.routeType} ]`)
        }
    }
}

export default new SideCar()