diff --git a/src/Microsoft.Diagnostics.Monitoring.RestServer/CorsConfiguration.cs b/src/Microsoft.Diagnostics.Monitoring.RestServer/CorsConfiguration.cs new file mode 100644 index 000000000..5de2ab996 --- /dev/null +++ b/src/Microsoft.Diagnostics.Monitoring.RestServer/CorsConfiguration.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Microsoft.Diagnostics.Monitoring.RestServer +{ + public class CorsConfiguration + { + public string AllowedOrigins { get; set; } + + public string[] GetOrigins() => AllowedOrigins?.Split(';'); + } +} diff --git a/src/Tools/dotnet-monitor/Startup.cs b/src/Tools/dotnet-monitor/Startup.cs index 00edf0338..65cb015c9 100644 --- a/src/Tools/dotnet-monitor/Startup.cs +++ b/src/Tools/dotnet-monitor/Startup.cs @@ -72,6 +72,13 @@ namespace Microsoft.Diagnostics.Monitoring app.UseHsts(); } + CorsConfiguration corsConfiguration = new CorsConfiguration(); + Configuration.Bind(nameof(CorsConfiguration), corsConfiguration); + if (!string.IsNullOrEmpty(corsConfiguration.AllowedOrigins)) + { + app.UseCors(builder => builder.WithOrigins(corsConfiguration.GetOrigins()).AllowAnyHeader().AllowAnyMethod()); + } + app.UseResponseCompression(); app.UseMvc(); }