From 159969483b64c5491b1d86b1aa4dac7b4b2a3ba1 Mon Sep 17 00:00:00 2001 From: Tom Gardham-Pallister Date: Mon, 13 Feb 2017 18:51:47 +0000 Subject: [PATCH] hacking away --- .../Middleware/OcelotMiddlewareExtensions.cs | 30 +++++++++++-------- .../ReturnsErrorTests.cs | 9 ++++-- .../TestConfiguration.cs | 2 +- test/Ocelot.ManualTest/Startup.cs | 5 ++-- 4 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/Ocelot/Middleware/OcelotMiddlewareExtensions.cs b/src/Ocelot/Middleware/OcelotMiddlewareExtensions.cs index 5ba19ca5..26b1638f 100644 --- a/src/Ocelot/Middleware/OcelotMiddlewareExtensions.cs +++ b/src/Ocelot/Middleware/OcelotMiddlewareExtensions.cs @@ -29,31 +29,37 @@ namespace Ocelot.Middleware /// /// /// - public static IApplicationBuilder UseOcelot(this IApplicationBuilder builder) + public static async Task UseOcelot(this IApplicationBuilder builder) { - var configuration = CreateConfiguration(builder).Result; - - builder.Map(configuration.AdministrationPath, x => - { - x.UseMvc(); - }); - - builder.UseOcelot(new OcelotMiddlewareConfiguration()); - + await CreateAdministrationArea(builder); + await builder.UseOcelot(new OcelotMiddlewareConfiguration()); return builder; } + private static async Task CreateAdministrationArea(IApplicationBuilder builder) + { + var configuration = await CreateConfiguration(builder); + + if(!string.IsNullOrEmpty(configuration.AdministrationPath)) + { + builder.Map(configuration.AdministrationPath, x => + { + x.UseMvc(); + }); + } + } + /// /// Registers Ocelot with a combination of default middlewares and optional middlewares in the configuration /// /// /// /// - public static IApplicationBuilder UseOcelot(this IApplicationBuilder builder, OcelotMiddlewareConfiguration middlewareConfiguration) + public static async Task UseOcelot(this IApplicationBuilder builder, OcelotMiddlewareConfiguration middlewareConfiguration) { - CreateConfiguration(builder); + await CreateAdministrationArea(builder); // This is registered to catch any global exceptions that are not handled builder.UseExceptionHandlerMiddleware(); diff --git a/test/Ocelot.AcceptanceTests/ReturnsErrorTests.cs b/test/Ocelot.AcceptanceTests/ReturnsErrorTests.cs index f9222b86..0d81b6df 100644 --- a/test/Ocelot.AcceptanceTests/ReturnsErrorTests.cs +++ b/test/Ocelot.AcceptanceTests/ReturnsErrorTests.cs @@ -21,7 +21,7 @@ namespace Ocelot.AcceptanceTests } [Fact] - public void should_return_response_200_and_foward_claim_as_header() + public void should_return_server_error() { var configuration = new FileConfiguration { @@ -29,9 +29,12 @@ namespace Ocelot.AcceptanceTests { new FileReRoute { - DownstreamPathTemplate = "http://localhost:53876/", + DownstreamPathTemplate = "/", UpstreamPathTemplate = "/", - UpstreamHttpMethod = "Get" + UpstreamHttpMethod = "Get", + DownstreamPort = 53876, + DownstreamHost = "localhost", + DownstreamScheme = "http", } } }; diff --git a/test/Ocelot.AcceptanceTests/TestConfiguration.cs b/test/Ocelot.AcceptanceTests/TestConfiguration.cs index ce802efb..6784391c 100644 --- a/test/Ocelot.AcceptanceTests/TestConfiguration.cs +++ b/test/Ocelot.AcceptanceTests/TestConfiguration.cs @@ -28,7 +28,7 @@ { var runTime = $"{oSDescription}-{osArchitecture}".ToLower(); - var configPath = $"./bin/Debug/netcoreapp{Version}/{runTime}/configuration.json"; + var configPath = $"./test/Ocelot.AcceptanceTests/bin/Debug/netcoreapp{Version}/{runTime}/configuration.json"; return configPath; } diff --git a/test/Ocelot.ManualTest/Startup.cs b/test/Ocelot.ManualTest/Startup.cs index 70448fcf..b187f6b4 100644 --- a/test/Ocelot.ManualTest/Startup.cs +++ b/test/Ocelot.ManualTest/Startup.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using CacheManager.Core; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; @@ -43,11 +44,11 @@ namespace Ocelot.ManualTest services.AddOcelot(); } - public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) + public async void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); - app.UseOcelot(); + await app.UseOcelot(); } } }