Skip to content

Commit

Permalink
Add CORS (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
idormenco committed Apr 4, 2021
1 parent fe3bf22 commit 74bf12e
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions Src/DeUrgenta.Api/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
Expand All @@ -33,6 +34,7 @@ public Startup(IConfiguration configuration, IWebHostEnvironment environment)
public List<ApiAuthenticationScheme> AuthSchemes { get; set; }

private string _swaggerClientName;
private string _corsPolicyName;

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
Expand Down Expand Up @@ -64,12 +66,22 @@ public void ConfigureServices(IServiceCollection services)
services.AddSwaggerFor(applicationAssemblies, Configuration);
services.AddMediatR(applicationAssemblies);

_corsPolicyName = "MyPolicy";
services.AddCors(o => o.AddPolicy(_corsPolicyName, builder =>
{
builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader();
}));

}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, DeUrgenta.Domain.DeUrgentaContext dbContext)
public void Configure(IApplicationBuilder app, Domain.DeUrgentaContext dbContext)
{
//dbContext.Database.Migrate();

dbContext.Database.Migrate();
app.UseCors(_corsPolicyName);

if (WebHostEnvironment.IsDevelopment())
{
Expand Down

0 comments on commit 74bf12e

Please sign in to comment.