Skip to content

Commit

Permalink
add CorsExtentions
Browse files Browse the repository at this point in the history
  • Loading branch information
samanazadi1996 committed Jun 8, 2024
1 parent 9cba817 commit e06154a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;

namespace CleanArchitecture.WebApi.Infrastracture.Extensions;

public static class CorsExtentions
{
public static IServiceCollection AddAnyCors(this IServiceCollection services)
{
return services.AddCors(x =>
{
x.AddPolicy("Any", b =>
{
b.AllowAnyOrigin();
b.AllowAnyHeader();
b.AllowAnyMethod();
});
});
}
public static IApplicationBuilder UseAnyCors(this IApplicationBuilder app)
{
return app.UseCors("Any");
}
}
12 changes: 2 additions & 10 deletions Source/Src/Presentation/CleanArchitecture.WebApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,7 @@
builder.Services.AddControllers();
builder.Services.AddFluentValidationAutoValidation();
builder.Services.AddSwaggerWithVersioning();
builder.Services.AddCors(x =>
{
x.AddPolicy("Any", b =>
{
b.AllowAnyOrigin();
b.AllowAnyHeader();
b.AllowAnyMethod();
});
});
builder.Services.AddAnyCors();
builder.Services.AddCustomLocalization(builder.Configuration);
builder.Services.AddHealthChecks();
builder.Host.UseSerilog((context, configuration) => configuration.ReadFrom.Configuration(context.Configuration));
Expand All @@ -68,7 +60,7 @@
}

app.UseCustomLocalization();
app.UseCors("Any");
app.UseAnyCors();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
Expand Down

0 comments on commit e06154a

Please sign in to comment.