From be8b06c6c4337709455b50b2c4356a0ec1ec4e86 Mon Sep 17 00:00:00 2001 From: Eric Nguyen Date: Sun, 6 Aug 2023 13:43:56 +0700 Subject: [PATCH] mix - clean up ocelot --- .../Domain/Extensions/ServiceExtension.cs | 9 +++ src/applications/Mixcore/Startup.cs | 7 --- src/applications/mixcore.gateway/ocelot.json | 30 +++++++++ .../Configurations/OcelotConfigurations.cs | 63 +++++++++++++++++++ 4 files changed, 102 insertions(+), 7 deletions(-) create mode 100644 src/platform/mix.shared/Models/Configurations/OcelotConfigurations.cs diff --git a/src/applications/Mixcore/Domain/Extensions/ServiceExtension.cs b/src/applications/Mixcore/Domain/Extensions/ServiceExtension.cs index bfd0c55ad..70a262d76 100644 --- a/src/applications/Mixcore/Domain/Extensions/ServiceExtension.cs +++ b/src/applications/Mixcore/Domain/Extensions/ServiceExtension.cs @@ -59,6 +59,15 @@ public static IApplicationBuilder UseMixRoutes(this IApplicationBuilder app) // pattern: "portal-apps/{appFolder:" + urlPathPattern + "}/{param1?}/{param2?}/{param3?}/{param4?}"); routes.MapFallbackToFile("/index.html"); }); + //app.MapWhen( + // context => + // { + // var path = context.Request.Path.Value.ToLower(); + // return + // path.StartsWith("/mix-app") || + // path.StartsWith("/mix-content"); + // }, + // config => config.UseStaticFiles()); return app; } diff --git a/src/applications/Mixcore/Startup.cs b/src/applications/Mixcore/Startup.cs index 51b794abf..e982c83bd 100644 --- a/src/applications/Mixcore/Startup.cs +++ b/src/applications/Mixcore/Startup.cs @@ -34,9 +34,6 @@ public void ConfigureServices(IServiceCollection services) services.AddMixAuthorize(Configuration); services.AddMixRoutes(); - // Must app Auth config after Add mixservice to init App config - services.AddMixOcelot(Configuration); - services.TryAddScoped(); } @@ -66,10 +63,6 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) Path.Combine(env.ContentRootPath, MixFolders.TemplatesFolder)) }); - if (GlobalConfigService.Instance.AppSettings.EnableOcelot) - { - app.UseMixOcelot(Configuration, env.IsDevelopment()); - } if (GlobalConfigService.Instance.AppSettings.IsHttps) { app.UseHttpsRedirection(); diff --git a/src/applications/mixcore.gateway/ocelot.json b/src/applications/mixcore.gateway/ocelot.json index c72d8f802..98e090db5 100644 --- a/src/applications/mixcore.gateway/ocelot.json +++ b/src/applications/mixcore.gateway/ocelot.json @@ -1,5 +1,35 @@ { "Routes": [ + { + "Priority": 0, + "DownstreamPathTemplate": "/{everything}", + "DownstreamScheme": "https", + "DownstreamHostAndPorts": [ + { + "Host": "localhost", + "Port": 5010 + } + ], + "UpstreamPathTemplate": "/{everything}", + "UpstreamHttpMethod": [ "Get", "Post", "Put", "Patch", "Delete" ], + "RateLimitOptions": { + "ClientWhitelist": [], + "EnableRateLimiting": true, + "Period": "1s", + "PeriodTimespan": 1, + "Limit": 10 + }, + "FileCacheOptions": { + "TtlSeconds": 120, + "Region": "VN" + }, + "HttpHandlerOptions": { + "AllowAutoRedirect": true, + "UseCookieContainer": true, + "UseTracing": true, + "MaxConnectionsPerServer": 20 + } + } ], "GlobalConfiguration": { "BaseUrl": "" diff --git a/src/platform/mix.shared/Models/Configurations/OcelotConfigurations.cs b/src/platform/mix.shared/Models/Configurations/OcelotConfigurations.cs new file mode 100644 index 000000000..16dc73bcd --- /dev/null +++ b/src/platform/mix.shared/Models/Configurations/OcelotConfigurations.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Mix.Shared.Models.Configurations +{ + public class OcelotConfigurations + { + public List Routes { get; set; } + public OcelotGlobalConfiguration GlobalConfiguration { get; set; } + } + + public class OcelotGlobalConfiguration + { + public OcelotRateLimitOptions RateLimitOptions { get; set; } + public OcelotHttpHandlerOptions HttpHandlerOptions { get; set; } + public string BaseUrl { get; set; } + } + + public class OcelotRoute + { + public int Priority { get; set; } + public string DownstreamPathTemplate { get; set; } + public string DownstreamScheme { get; set; } + public OcelotHost DownstreamHostAndPorts { get; set; } + public string UpstreamPathTemplate { get; set; } + public string[] UpstreamHttpMethod { get; set; } + public OcelotRateLimitOptions RateLimitOptions { get; set; } + public OcelotFileCacheOptions FileCacheOptions { get; set; } + public OcelotHttpHandlerOptions HttpHandlerOptions { get; set; } + } + + public class OcelotHttpHandlerOptions + { + public bool AllowAutoRedirect { get; set; } + public bool UseCookieContainer { get; set; } + public bool UseTracing { get; set; } + public int MaxConnectionsPerServer { get; set; } + } + + public class OcelotFileCacheOptions + { + public int TtlSeconds { get; set; } + public string Region { get; set; } + } + + public class OcelotRateLimitOptions + { + public string[] ClientWhitelist { get; set; } + public bool EnableRateLimiting { get; set; } + public string Period { get; set; } + public int PeriodTimespan { get; set; } + public int Limit { get; set; } + } + + public class OcelotHost + { + public string Host { get; set; } + public int Port { get; set; } + } +}