-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f8eb5e
commit c117911
Showing
2 changed files
with
35 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
namespace Nuages.Web; | ||
|
||
public static class CorsConfigExtensions | ||
{ | ||
// ReSharper disable once MemberCanBePrivate.Global | ||
public const string AllowSpecificOrigins = "AllowSpecificOrigins"; | ||
private const string AllowAnyOrigins = "AllowAnyOrigins"; | ||
|
||
// ReSharper disable once UnusedMember.Global | ||
public static void AddCors(this IServiceCollection services, string[] domains) | ||
{ | ||
services.AddCors(options => | ||
{ | ||
options.AddPolicy(AllowSpecificOrigins, | ||
builder => | ||
{ | ||
builder.WithOrigins(domains) | ||
.AllowCredentials() | ||
.AllowAnyMethod() | ||
.AllowAnyHeader(); | ||
}); | ||
|
||
|
||
options.AddPolicy(AllowAnyOrigins, | ||
builder => | ||
{ | ||
builder.AllowCredentials() | ||
.SetIsOriginAllowed(_ => true) | ||
.AllowAnyMethod() | ||
.AllowAnyHeader(); | ||
}); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters