public static IApplicationBuilder UseOcelotConfigEditor( this IApplicationBuilder app, ConfigEditorOptions configEditorOptions = null) { var services = app.ApplicationServices; var env = services.GetService <IHostingEnvironment>(); var config = services.GetService <IConfiguration>(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Editor/Error"); app.UseHsts(); } var configPath = config["OcelotConfigEditor:Path"]; var pathMatch = configPath ?? (configEditorOptions?.Path ?? "cfgedt").Trim('/'); var authSettings = services.GetService <AuthorizeSettings>(); if (authSettings.HasAuthentication) { app.UseWhen(context => context.Request.Path.StartsWithSegments($"/{pathMatch}"), appBuilder => { appBuilder.UseHttpsRedirection(); appBuilder.UseAuthentication(); }); } app.UseMvc( routes => { routes.MapRoute( "ConfigEditor", $"{pathMatch}/{{controller=Editor}}/{{action=Index}}/{{id?}}", null, null, new { Namespace = "Ocelot.ConfigEditor.Editor.Controllers" }); }); var appLifetime = services.GetService <IApplicationLifetime>(); appLifetime.ApplicationStarted.Register(() => { var configEditorService = services.GetService <IConfigEditorService>(); configEditorService.RemoveReloadFlag(); }); return(app); }
public static IApplicationBuilder UseOcelotConfigEditor( this IApplicationBuilder app, ConfigEditorOptions configEditorOptions = null) { var services = app.ApplicationServices; var reload = services.GetService <IReloadService>(); reload.RemoveReloadFlag(); if (configEditorOptions == null || configEditorOptions.Paths == null || configEditorOptions.Paths.Length != 2) { throw new System.Exception("路径数组必需有两个值,每一个为手动录入配置,第一个为自动配置"); } app.UseMvc( routes => { routes.MapRoute( "ConfigEditor", $"{configEditorOptions.Paths[0]}/{{controller=Editor}}/{{action=Index}}/{{id?}}", null, new { IsLocal = new LocalhostRouteConstraint() }, new { Namespace = "Ocelot.ConfigEditor.Editor.Controllers" }); routes.MapRoute( "ConfigCreate", $"{configEditorOptions.Paths[1]}/{{controller=Editor}}/{{action=AutoCreate}}/{{id?}}", null, new { IsLocal = new LocalhostRouteConstraint() }, new { Namespace = "Ocelot.ConfigEditor.Editor.Controllers" }); // routes.MapRoute( //"ConfigCreateAction", //$"{"getserver"}/{{controller=Editor}}/{{action=GetActionByServer}}/{{id?}}", //null, //new { IsLocal = new LocalhostRouteConstraint() }, //new { Namespace = "Ocelot.ConfigEditor.Editor.Controllers" }); }); return(app); }
public static IApplicationBuilder UseOcelotConfigEditor( this IApplicationBuilder app, ConfigEditorOptions configEditorOptions = null) { var services = app.ApplicationServices; var reload = services.GetService <IReloadService>(); reload.RemoveReloadFlag(); var pathMatch = (configEditorOptions?.Path ?? "cfgedt").Trim('/'); app.UseMvc( routes => { routes.MapRoute( "ConfigEditor", $"{pathMatch}/{{controller=Editor}}/{{action=Index}}/{{id?}}", null, new { IsLocal = new LocalhostRouteConstraint() }, new { Namespace = "Ocelot.ConfigEditor.Editor.Controllers" }); }); return(app); }