Esempio n. 1
0
        private void BuildRoutes(IRouteBuilder routeBuilder, Module module, Route route)
        {
            var upstream = string.IsNullOrWhiteSpace(route.Upstream) ? string.Empty : route.Upstream;

            if (!string.IsNullOrWhiteSpace(module.Path))
            {
                var modulePath = module.Path.EndsWith("/") ? module.Path : $"{module.Path}/";
                if (upstream.StartsWith("/"))
                {
                    upstream = upstream.Substring(1, upstream.Length - 1);
                }

                if (upstream.EndsWith("/"))
                {
                    upstream = upstream.Substring(0, upstream.Length - 1);
                }

                upstream = $"{modulePath}{upstream}";
            }

            if (string.IsNullOrWhiteSpace(upstream))
            {
                upstream = "/";
            }

            route.Upstream = upstream;
            var routeConfig = _routeConfigurator.Configure(module, route);

            _methods[route.Method](routeBuilder, route.Upstream, routeConfig);
        }
Esempio n. 2
0
        public Action <IEndpointRouteBuilder> Build() => routeBuilder =>
        {
            foreach (var module in _options.Modules.Where(m => m.Value.Enabled != false))
            {
                _logger.LogInformation($"Building routes for the module: '{module.Key}'");
                foreach (var route in module.Value.Routes)
                {
                    if (string.IsNullOrWhiteSpace(route.Method) && route.Methods is null)
                    {
                        throw new ArgumentException("Both, route 'method' and 'methods' cannot be empty.");
                    }

                    route.Upstream = _upstreamBuilder.Build(module.Value, route);
                    var routeConfig = _routeConfigurator.Configure(module.Value, route);

                    if (!string.IsNullOrWhiteSpace(route.Method))
                    {
                        _methods[route.Method](routeBuilder, route.Upstream, routeConfig);
                        AddEndpointDefinition(route.Method, route.Upstream);
                    }

                    if (route.Methods is null)
                    {
                        continue;
                    }

                    foreach (var method in route.Methods)
                    {
                        var methodType = method.ToLowerInvariant();
                        _methods[methodType](routeBuilder, route.Upstream, routeConfig);
                        AddEndpointDefinition(methodType, route.Upstream);
                    }
                }
            }
        };
Esempio n. 3
0
 public Action <IEndpointRouteBuilder> Build()
 => routeBuilder =>
 {
     foreach (var module in _options.Modules.Where(m => m.Value.Enabled != false))
     {
         _logger.LogInformation($"Building routes for the module: '{module.Key}'");
         foreach (var route in module.Value.Routes)
         {
             route.Upstream = _upstreamBuilder.Build(module.Value, route);
             var routeConfig = _routeConfigurator.Configure(module.Value, route);
             _methods[route.Method](routeBuilder, route.Upstream, routeConfig);
         }
     }
 };