Browse Source

feat(cors): add missing cors settings

pull/454/head
cKey 4 years ago
parent
commit
3e23c456bf
  1. 3
      aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/appsettings.Development.json
  2. 3
      aspnet-core/services/LY.MicroService.LocalizationManagement.HttpApi.Host/appsettings.Development.json
  3. 3
      aspnet-core/services/LY.MicroService.PlatformManagement.HttpApi.Host/appsettings.Development.json
  4. 2
      aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/appsettings.Development.json
  5. 2
      aspnet-core/services/LY.MicroService.identityServer.HttpApi.Host/appsettings.Development.json
  6. 2
      aspnet-core/services/LY.MicroService.identityServer/appsettings.Development.json
  7. 28
      gateways/internal/LINGYUN.MicroService.Internal.ApiGateway/src/LINGYUN.MicroService.Internal.ApiGateway/InternalApiGatewayModule.Configure.cs
  8. 2
      gateways/internal/LINGYUN.MicroService.Internal.ApiGateway/src/LINGYUN.MicroService.Internal.ApiGateway/InternalApiGatewayModule.cs
  9. 3
      gateways/internal/LINGYUN.MicroService.Internal.ApiGateway/src/LINGYUN.MicroService.Internal.ApiGateway/appsettings.Development.json

3
aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/appsettings.Development.json

@ -14,7 +14,8 @@
"KnownProxies": [ "KnownProxies": [
"localhost" "localhost"
] ]
} },
"CorsOrigins": "http://localhost:3100"
}, },
"ConnectionStrings": { "ConnectionStrings": {
"Default": "Server=localhost;Database=Platform;User Id=root;Password=123456", "Default": "Server=localhost;Database=Platform;User Id=root;Password=123456",

3
aspnet-core/services/LY.MicroService.LocalizationManagement.HttpApi.Host/appsettings.Development.json

@ -8,7 +8,8 @@
"tag": "Localization" "tag": "Localization"
}, },
"App": { "App": {
"TrackingEntitiesChanged": true "TrackingEntitiesChanged": true,
"CorsOrigins": "http://localhost:3100"
}, },
"ConnectionStrings": { "ConnectionStrings": {
"Default": "Server=localhost;Database=Platform;User Id=root;Password=123456", "Default": "Server=localhost;Database=Platform;User Id=root;Password=123456",

3
aspnet-core/services/LY.MicroService.PlatformManagement.HttpApi.Host/appsettings.Development.json

@ -13,7 +13,8 @@
"KnownProxies": [ "KnownProxies": [
"localhost" "localhost"
] ]
} },
"CorsOrigins": "http://localhost:3100"
}, },
"RemoteServices": { "RemoteServices": {
"AbpIdentity": { "AbpIdentity": {

2
aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/appsettings.Development.json

@ -8,7 +8,7 @@
"tag": "Message" "tag": "Message"
}, },
"App": { "App": {
"CorsOrigins": "http://localhost:9527,http://localhost:30000,http://localhost:3100", "CorsOrigins": "http://localhost:3100",
"Forwarded": { "Forwarded": {
"ForwardedHeaders": 5, "ForwardedHeaders": 5,
"KnownProxies": [ "KnownProxies": [

2
aspnet-core/services/LY.MicroService.identityServer.HttpApi.Host/appsettings.Development.json

@ -10,7 +10,7 @@
"App": { "App": {
"TrackingEntitiesChanged": true, "TrackingEntitiesChanged": true,
"SelfUrl": "http://localhost:30015/", "SelfUrl": "http://localhost:30015/",
"CorsOrigins": "http://localhost:4200,http://localhost:9527,http://localhost:3100" "CorsOrigins": "http://localhost:3100"
}, },
"ConnectionStrings": { "ConnectionStrings": {
"Default": "Server=localhost;Database=IdentityServer;User Id=root;Password=123456", "Default": "Server=localhost;Database=IdentityServer;User Id=root;Password=123456",

2
aspnet-core/services/LY.MicroService.identityServer/appsettings.Development.json

@ -10,7 +10,7 @@
"App": { "App": {
"TrackingEntitiesChanged": true, "TrackingEntitiesChanged": true,
"SelfUrl": "http://localhost:44385/", "SelfUrl": "http://localhost:44385/",
"CorsOrigins": "http://localhost:4200,http://localhost:9527,http://localhost:3100" "CorsOrigins": "http://localhost:3100"
}, },
"AppSelfUrl": "http://localhost:44385/", "AppSelfUrl": "http://localhost:44385/",
"ConnectionStrings": { "ConnectionStrings": {

28
gateways/internal/LINGYUN.MicroService.Internal.ApiGateway/src/LINGYUN.MicroService.Internal.ApiGateway/InternalApiGatewayModule.Configure.cs

@ -3,6 +3,7 @@ using LINGYUN.MicroService.Internal.ApiGateway.Localization;
using LINGYUN.MicroService.Internal.ApiGateway.Ocelot.Configuration.Repository; using LINGYUN.MicroService.Internal.ApiGateway.Ocelot.Configuration.Repository;
using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Routing; using Microsoft.AspNetCore.Routing;
@ -17,6 +18,7 @@ using Ocelot.Multiplexer;
using Ocelot.Provider.Polly; using Ocelot.Provider.Polly;
using StackExchange.Redis; using StackExchange.Redis;
using System; using System;
using System.Linq;
using System.Text.Encodings.Web; using System.Text.Encodings.Web;
using System.Text.Unicode; using System.Text.Unicode;
using Volo.Abp.Caching; using Volo.Abp.Caching;
@ -29,6 +31,8 @@ namespace LINGYUN.MicroService.Internal.ApiGateway
{ {
public partial class InternalApiGatewayModule public partial class InternalApiGatewayModule
{ {
protected const string DefaultCorsPolicyName = "Default";
private void PreConfigureApp() private void PreConfigureApp()
{ {
AbpSerilogEnrichersConsts.ApplicationName = "Internal-ApiGateWay"; AbpSerilogEnrichersConsts.ApplicationName = "Internal-ApiGateWay";
@ -178,6 +182,30 @@ namespace LINGYUN.MicroService.Internal.ApiGateway
}); });
} }
private void ConfigureCors(IServiceCollection services, IConfiguration configuration)
{
services.AddCors(options =>
{
options.AddPolicy(DefaultCorsPolicyName, builder =>
{
builder
.WithOrigins(
configuration["App:CorsOrigins"]
.Split(",", StringSplitOptions.RemoveEmptyEntries)
.Select(o => o.RemovePostFix("/"))
.ToArray()
)
.WithAbpExposedHeaders()
// 引用 LINGYUN.Abp.AspNetCore.Mvc.Wrapper 包时可替换为 WithAbpWrapExposedHeaders
.WithExposedHeaders("_AbpWrapResult", "_AbpDontWrapResult")
.SetIsOriginAllowedToAllowWildcardSubdomains()
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials();
});
});
}
private void ConfigureSecurity(IServiceCollection services, IConfiguration configuration, bool isDevelopment = false) private void ConfigureSecurity(IServiceCollection services, IConfiguration configuration, bool isDevelopment = false)
{ {
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)

2
gateways/internal/LINGYUN.MicroService.Internal.ApiGateway/src/LINGYUN.MicroService.Internal.ApiGateway/InternalApiGatewayModule.cs

@ -47,6 +47,7 @@ namespace LINGYUN.MicroService.Internal.ApiGateway
ConfigureMvc(context.Services); ConfigureMvc(context.Services);
ConfigureSwagger(context.Services); ConfigureSwagger(context.Services);
ConfigureCors(context.Services, configuration);
ConfigureOcelot(context.Services, configuration); ConfigureOcelot(context.Services, configuration);
} }
@ -56,6 +57,7 @@ namespace LINGYUN.MicroService.Internal.ApiGateway
app.UseAuditing(); app.UseAuditing();
app.UseStaticFiles(); app.UseStaticFiles();
app.UseRouting(); app.UseRouting();
app.UseCors(DefaultCorsPolicyName);
app.UseAuthentication(); app.UseAuthentication();
app.UseAbpClaimsMap(); app.UseAbpClaimsMap();
app.MapWhen( app.MapWhen(

3
gateways/internal/LINGYUN.MicroService.Internal.ApiGateway/src/LINGYUN.MicroService.Internal.ApiGateway/appsettings.Development.json

@ -7,6 +7,9 @@
"name": "ApiGateway", "name": "ApiGateway",
"tag": "ApiGateway" "tag": "ApiGateway"
}, },
"App": {
"CorsOrigins": "http://localhost:3100"
},
"ApiGateway": { "ApiGateway": {
"AppId": "TEST-APP", "AppId": "TEST-APP",
"DownstreamOpenApis": [ "DownstreamOpenApis": [

Loading…
Cancel
Save