route method

V2RayConfigBuilder route({
  1. List<String>? domains,
  2. List<String>? ips,
  3. List<String>? inboundTags,
  4. String? outboundTag,
  5. String? balancerTag,
})

Route matching domains or IP ranges to an outbound or balancer.

Implementation

V2RayConfigBuilder route({
  List<String>? domains,
  List<String>? ips,
  List<String>? inboundTags,
  String? outboundTag,
  String? balancerTag,
}) {
  if ((outboundTag == null) == (balancerTag == null)) {
    throw ArgumentError(
        'Provide exactly one of outboundTag or balancerTag');
  }
  if ((domains == null || domains.isEmpty) &&
      (ips == null || ips.isEmpty) &&
      (inboundTags == null || inboundTags.isEmpty)) {
    throw ArgumentError('A route needs at least one matching condition');
  }
  return addRoutingRule({
    'type': 'field',
    if (domains != null && domains.isNotEmpty) 'domain': domains,
    if (ips != null && ips.isNotEmpty) 'ip': ips,
    if (inboundTags != null && inboundTags.isNotEmpty)
      'inboundTag': inboundTags,
    if (outboundTag != null) 'outboundTag': outboundTag,
    if (balancerTag != null) 'balancerTag': balancerTag,
  });
}