In this section, we are going to change our CORS configuration to reference appsettings.json so that it's not hardcoded. We are then going to create separate appsettings.json files for staging and production as well for working locally in development. Let's open our backend project in Visual Studio and carry out the following steps:
- In the StartUp class in the ConfigureServices method, let's change our call to the AddCors method to the following:
services.AddCors(options => options.AddPolicy("CorsPolicy",
builder => builder
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials()
.WithOrigins(Configuration["Frontend"])));
We have simply changed the origin to reference a Frontend configuration setting instead of...