Skip to content

Commit

Permalink
mix - clean up ocelot
Browse files Browse the repository at this point in the history
  • Loading branch information
nhathoang989 committed Aug 6, 2023
1 parent 7463c4c commit be8b06c
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
7 changes: 0 additions & 7 deletions src/applications/Mixcore/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ public void ConfigureServices(IServiceCollection services)
services.AddMixAuthorize<MixCmsAccountContext>(Configuration);
services.AddMixRoutes();

// Must app Auth config after Add mixservice to init App config
services.AddMixOcelot(Configuration);

services.TryAddScoped<MixcorePostService>();
}

Expand Down Expand Up @@ -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();
Expand Down
30 changes: 30 additions & 0 deletions src/applications/mixcore.gateway/ocelot.json
Original file line number Diff line number Diff line change
@@ -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": ""
Expand Down
Original file line number Diff line number Diff line change
@@ -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<OcelotRoute> 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; }
}
}

0 comments on commit be8b06c

Please sign in to comment.