From 468a13a9de0d95319ef7d6d41b61d17282bdce82 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Thu, 20 Oct 2022 16:49:33 +0800 Subject: [PATCH] Improve RemoveUnnecessaryPortsStep --- .../Templates/RemoveUnnecessaryPortsStep.cs | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/RemoveUnnecessaryPortsStep.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/RemoveUnnecessaryPortsStep.cs index 0df8b596f88..be5948c8b6c 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/RemoveUnnecessaryPortsStep.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/RemoveUnnecessaryPortsStep.cs @@ -32,23 +32,28 @@ private static void RemoveUnnecessaryHttpApiHostPorts(ProjectBuildContext contex if (context.BuildArgs.UiFramework != UiFramework.Angular) { - appJson.Property("ClientUrl")?.Remove(); - portsToRemoveFromCors.Add("4200"); + var clientUrl = appJson.Property("ClientUrl")?.ToString(); + portsToRemoveFromCors.Add("http://localhost:4200"); + + if (!clientUrl.IsNullOrWhiteSpace()) + { + httpApiHostAppSettings.SetContent(httpApiHostAppSettings.Content.Replace(clientUrl, string.Empty)); + } } - + if (context.BuildArgs.UiFramework != UiFramework.Blazor) { - portsToRemoveFromCors.Add("44307"); + portsToRemoveFromCors.Add("https://localhost:44307"); } + if (appJson["CorsOrigins"] != null) { - appJson["CorsOrigins"] = string.Join(",", - appJson["CorsOrigins"].ToString().Split(",").Where(u => !portsToRemoveFromCors.Any(u.EndsWith)) - ); + var corsOrigins = appJson["CorsOrigins"].ToString(); + var newCorsOrigins = string.Join(",", corsOrigins.Split(',').Where(x => !portsToRemoveFromCors.Contains(x))); + + httpApiHostAppSettings.SetContent(httpApiHostAppSettings.Content.Replace(corsOrigins, newCorsOrigins)); } - - httpApiHostAppSettings.SetContent(JsonConvert.SerializeObject(appSettingsJson, Formatting.Indented)); } private static void RemoveUnnecessaryDbMigratorClients(ProjectBuildContext context)