Skip to content

Commit 17eb33c

Browse files
authored
Merge pull request #22 from barzin144/fix-cors
fix cors
2 parents 640d433 + 4ab7cac commit 17eb33c

File tree

4 files changed

+7
-3
lines changed

4 files changed

+7
-3
lines changed

IoCConfig/ConfigureServicesExtensions.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ namespace IoCConfig
1919
{
2020
public static class ConfigureServicesExtensions
2121
{
22-
public static void AddCustomCors(this IServiceCollection services)
22+
public static void AddCustomCors(this IServiceCollection services, IConfiguration configuration)
2323
{
2424
services.AddCors(options =>
2525
options.AddPolicy("CorsPolicy",
2626
builder => builder
27-
.WithOrigins("http://localhost:5000")
27+
.WithOrigins(configuration["Cors:Origins"])
2828
.AllowAnyMethod()
2929
.AllowAnyHeader()
3030
.SetIsOriginAllowed((host) => true)

WebApi/Program.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
services.AddCustomOptions(configuration);
1111
services.AddCustomServices();
1212
services.AddCustomAuthentication(configuration);
13-
services.AddCustomCors();
13+
services.AddCustomCors(configuration);
1414
services.AddControllers();
1515
services.AddCustomSwagger();
1616
services.AddCustomMongoDbService(configuration);

WebApi/appsettings.json

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
]
2020
},
2121
"EnableSwagger": true,
22+
"Cors": {
23+
"Origins": "http://localhost:5000"
24+
},
2225
"Jwt": {
2326
"PrivateKey": "",
2427
"Issuer": "https://localhost:8001",

docker-compose.yml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ services:
1313
ASPNETCORE_URLS: "https://+;http://+"
1414
ASPNETCORE_Kestrel__Certificates__Default__Path: "/https/aspnetcore.pfx"
1515
ASPNETCORE_Kestrel__Certificates__Default__Password: "1234567890"
16+
Cors__Origins: "http://localhost:5000"
1617
volumes:
1718
- type: bind
1819
source: ./aspnetcore.pfx

0 commit comments

Comments
 (0)