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 }); }
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); }
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); }