You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.3 KiB
41 lines
1.3 KiB
using Microsoft.Extensions.DependencyInjection;
|
|
using Znyc.CloudCar.Configuration;
|
|
|
|
namespace Znyc.CloudCar.Core.Config
|
|
{
|
|
public static class CoreSetup
|
|
{
|
|
|
|
public static void AddCoresSetup(this IServiceCollection services)
|
|
{
|
|
if (services == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(services));
|
|
}
|
|
services.AddCors(c =>
|
|
{
|
|
if (!AppSettingsConstVars.CorsEnableAllIPs)
|
|
{
|
|
c.AddPolicy(AppSettingsConstVars.CorsPolicyName, policy =>
|
|
{
|
|
policy.WithOrigins(AppSettingsConstVars.CorsIPs.Split(','));
|
|
policy.AllowAnyHeader();
|
|
policy.AllowAnyMethod();
|
|
policy.AllowCredentials();
|
|
});
|
|
}
|
|
else
|
|
{
|
|
//允许任意跨域请求
|
|
c.AddPolicy(AppSettingsConstVars.CorsPolicyName, policy =>
|
|
{
|
|
policy.SetIsOriginAllowed((host) => true)
|
|
.AllowAnyHeader()
|
|
.AllowAnyMethod()
|
|
.AllowCredentials();
|
|
});
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|