示例#1
0
        public ProxyOptions GetOptions(EBasePaths path)
        {
            InMemoryServicePaths inMemoryServices = InMemoryServicePaths.Instance();
            var service = inMemoryServices.GetService(path);

            var(scheme, host, port) = GetUriComponents(service.Config.UriBase);
            return(new ProxyOptions()
            {
                Scheme = scheme,
                Host = host,
                Port = port
            });
        }
示例#2
0
        private Uri GetCurrentUri(HttpContext context)
        {
            InMemoryServicePaths memory = InMemoryServicePaths.Instance();

            List <ServiceInitialPath> services = memory.GetServices(context.Request.Path);

            ServiceInitialPath service = services?.FirstOrDefault();

            if (service is null)
            {
                return(null);
            }
            return(service.Config.UriBase);
        }
示例#3
0
        public static IApplicationBuilder UseProxyServer(this IApplicationBuilder builder)
        {
            //TODO: resolver por injeção de dependência
            InMemoryServicePaths path = InMemoryServicePaths.Instance();

            var services = path.GetServices();

            foreach (var service in services)
            {
                builder.MapWhen((HttpContext context) => {
                    ApiConfig serviceConfig = service.Config;
                    bool routeIsOfService   = serviceConfig.RegisteredControllers.Any(x => context.Request.Path.Value.ToLower().Contains(x.Path.ToLower()));
                    if (routeIsOfService)
                    {
                        context.Request.Path = serviceConfig.BasePathWithoutPortOrHost + context.Request.Path.Value;
                    }
                    return(routeIsOfService);
                }, b => b.RunProxy(new ProxyConfiguration()
                                   .GetOptions((EBasePaths)Enum.Parse(typeof(EBasePaths), service.Path))
                                   ));
            }

            return(builder);
        }