From 83e9126a5d56de8a1af5360fff7d5a02deba7313 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Andr=C3=A9?= Date: Tue, 12 Nov 2019 15:53:00 +0100 Subject: [PATCH] Fix the setting aboout Cors url --- Back/skydiveLogs-api/Startup.cs | 6 +++++- Back/skydiveLogs-api/appsettings.Development.json | 11 +++++++---- Back/skydiveLogs-api/appsettings.Release.json | 9 +++++---- Back/skydiveLogs-api/appsettings.json | 9 +++++++-- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/Back/skydiveLogs-api/Startup.cs b/Back/skydiveLogs-api/Startup.cs index d97f46a..2252988 100644 --- a/Back/skydiveLogs-api/Startup.cs +++ b/Back/skydiveLogs-api/Startup.cs @@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using System.Linq; using skydiveLogs_api.Ioc; using AutoMapper; @@ -23,12 +24,15 @@ namespace skydiveLogs_api services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); // CORS + var corsConf = Configuration.GetSection("Cors") + .GetChildren() + .ToDictionary(d => d.Key, d => d.Value); services.AddCors(options => { options.AddDefaultPolicy( builder => { - builder.WithOrigins(Configuration.GetSection("AllowedHosts").Value) + builder.WithOrigins(corsConf["FrontUrl"]) .AllowAnyHeader() .AllowAnyMethod(); }); diff --git a/Back/skydiveLogs-api/appsettings.Development.json b/Back/skydiveLogs-api/appsettings.Development.json index 2d0df14..df5d901 100644 --- a/Back/skydiveLogs-api/appsettings.Development.json +++ b/Back/skydiveLogs-api/appsettings.Development.json @@ -1,12 +1,15 @@ { "Logging": { "LogLevel": { - "Default": "Warning", - "System": "Warning", - "Microsoft": "Warning" + "Default": "Information", + "System": "Information", + "Microsoft": "Information" } }, - "AllowedHosts": "http://localhost:4200", + "Cors": { + "FrontUrl": "http://localhost:4200" + }, + "AllowedHosts": "*", "ConnectionStrings": { "DefaultConnection": "Filename=./Data/JumpsDb.db" } diff --git a/Back/skydiveLogs-api/appsettings.Release.json b/Back/skydiveLogs-api/appsettings.Release.json index 53db5ad..b4d0426 100644 --- a/Back/skydiveLogs-api/appsettings.Release.json +++ b/Back/skydiveLogs-api/appsettings.Release.json @@ -1,12 +1,13 @@ { "Logging": { "LogLevel": { - "Default": "Debug", - "System": "Information", - "Microsoft": "Information" + "Default": "Warning" } }, - "AllowedHosts": "http://skydivelogsangular.z6.web.core.windows.net", + "Cors": { + "FrontUrl": "http://skydivelogsangular.z6.web.core.windows.net" + }, + "AllowedHosts": "*", "ConnectionStrings": { "DefaultConnection": "Filename=./Data/JumpsDb.db" } diff --git a/Back/skydiveLogs-api/appsettings.json b/Back/skydiveLogs-api/appsettings.json index 4aa247b..a464752 100644 --- a/Back/skydiveLogs-api/appsettings.json +++ b/Back/skydiveLogs-api/appsettings.json @@ -1,10 +1,15 @@ { "Logging": { "LogLevel": { - "Default": "Warning" + "Default": "Debug", + "System": "Information", + "Microsoft": "Information" } }, - "AllowedHosts": "http://localhost:4200", + "Cors": { + "FrontUrl": "http://localhost:4200" + }, + "AllowedHosts": "*", "ConnectionStrings": { "DefaultConnection": "Filename=./Data/JumpsDb.db" }