mirror of
				https://github.com/nsnail/Ocelot.git
				synced 2025-11-04 09:15:27 +08:00 
			
		
		
		
	started messing around with admin area
This commit is contained in:
		@@ -85,7 +85,7 @@ namespace Ocelot.Configuration.Creator
 | 
			
		||||
                reRoutes.Add(ocelotReRoute);
 | 
			
		||||
            }
 | 
			
		||||
            
 | 
			
		||||
            return new OcelotConfiguration(reRoutes);
 | 
			
		||||
            return new OcelotConfiguration(reRoutes, _options.Value.GlobalConfiguration.AdministrationPath);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private async Task<ReRoute> SetUpReRoute(FileReRoute fileReRoute, FileGlobalConfiguration globalConfiguration)
 | 
			
		||||
 
 | 
			
		||||
@@ -8,5 +8,6 @@
 | 
			
		||||
        }
 | 
			
		||||
        public string RequestIdKey { get; set; }
 | 
			
		||||
        public FileServiceDiscoveryProvider ServiceDiscoveryProvider {get;set;}
 | 
			
		||||
        public string AdministrationPath {get;set;}
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -5,5 +5,6 @@ namespace Ocelot.Configuration
 | 
			
		||||
    public interface IOcelotConfiguration
 | 
			
		||||
    {
 | 
			
		||||
        List<ReRoute> ReRoutes { get; }
 | 
			
		||||
        string AdministrationPath {get;}
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -4,11 +4,13 @@ namespace Ocelot.Configuration
 | 
			
		||||
{
 | 
			
		||||
    public class OcelotConfiguration : IOcelotConfiguration
 | 
			
		||||
    {
 | 
			
		||||
        public OcelotConfiguration(List<ReRoute> reRoutes)
 | 
			
		||||
        public OcelotConfiguration(List<ReRoute> reRoutes, string administrationPath)
 | 
			
		||||
        {
 | 
			
		||||
            ReRoutes = reRoutes;
 | 
			
		||||
            AdministrationPath = administrationPath;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public List<ReRoute> ReRoutes { get; }
 | 
			
		||||
        public string AdministrationPath {get;}
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -18,6 +18,7 @@ namespace Ocelot.Middleware
 | 
			
		||||
    using System.Threading.Tasks;
 | 
			
		||||
    using Authorisation.Middleware;
 | 
			
		||||
    using Microsoft.AspNetCore.Http;
 | 
			
		||||
    using Ocelot.Configuration;
 | 
			
		||||
    using Ocelot.Configuration.Provider;
 | 
			
		||||
    using Ocelot.LoadBalancer.Middleware;
 | 
			
		||||
 | 
			
		||||
@@ -30,9 +31,9 @@ namespace Ocelot.Middleware
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        public static IApplicationBuilder UseOcelot(this IApplicationBuilder builder)
 | 
			
		||||
        {
 | 
			
		||||
            CreateConfiguration(builder);
 | 
			
		||||
            var configuration = CreateConfiguration(builder).Result;
 | 
			
		||||
 | 
			
		||||
            builder.Map("/admin", x => 
 | 
			
		||||
            builder.Map(configuration.AdministrationPath, x => 
 | 
			
		||||
            {
 | 
			
		||||
               x.UseMvc();
 | 
			
		||||
            });
 | 
			
		||||
@@ -131,16 +132,19 @@ namespace Ocelot.Middleware
 | 
			
		||||
            return builder;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private static void CreateConfiguration(IApplicationBuilder builder)
 | 
			
		||||
        private static async Task<IOcelotConfiguration> CreateConfiguration(IApplicationBuilder builder)
 | 
			
		||||
        {
 | 
			
		||||
            var configProvider = (IOcelotConfigurationProvider)builder.ApplicationServices.GetService(typeof(IOcelotConfigurationProvider));
 | 
			
		||||
            
 | 
			
		||||
            var config = configProvider.Get();
 | 
			
		||||
            var config = await configProvider.Get();
 | 
			
		||||
            
 | 
			
		||||
            if(config == null)
 | 
			
		||||
            //todo move this to config validators
 | 
			
		||||
            if(config == null || config.Data == null || config.IsError)
 | 
			
		||||
            {
 | 
			
		||||
                throw new Exception("Unable to start Ocelot: configuration was null");
 | 
			
		||||
                throw new Exception("Unable to start Ocelot: configuration was invalid");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return config.Data;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private static void UseIfNotNull(this IApplicationBuilder builder, Func<HttpContext, Func<Task>, Task> middleware)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user