diff --git a/Blog.Core.Api/Blog.Core.Api.csproj b/Blog.Core.Api/Blog.Core.Api.csproj index 77d681f1..9580f25f 100644 --- a/Blog.Core.Api/Blog.Core.Api.csproj +++ b/Blog.Core.Api/Blog.Core.Api.csproj @@ -11,6 +11,10 @@ true + + true + + ..\Blog.Core.Api\Blog.Core.xml 1701;1702;1591 @@ -22,6 +26,7 @@ false + disable @@ -51,6 +56,7 @@ + diff --git a/Blog.Core.Api/appsettings.apollo.json b/Blog.Core.Api/CustomConfig/Apollo.json similarity index 98% rename from Blog.Core.Api/appsettings.apollo.json rename to Blog.Core.Api/CustomConfig/Apollo.json index 826c75ca..0ca96f5b 100644 --- a/Blog.Core.Api/appsettings.apollo.json +++ b/Blog.Core.Api/CustomConfig/Apollo.json @@ -1,4 +1,4 @@ -{ +{ //apollo 配置 "Apollo": { "Enable": false, diff --git a/Blog.Core.Api/CustomConfig/AppSettings.json b/Blog.Core.Api/CustomConfig/AppSettings.json new file mode 100644 index 00000000..a9f746b1 --- /dev/null +++ b/Blog.Core.Api/CustomConfig/AppSettings.json @@ -0,0 +1,40 @@ +{ + "AppSettings": { + "RedisCachingAOP": { + "Enabled": false + }, + "MemoryCachingAOP": { + "Enabled": true + }, + "LogAOP": { + "Enabled": true, + "LogToFile": { + "Enabled": false + }, + "LogToDB": { + "Enabled": true + } + }, + "TranAOP": { + "Enabled": true + }, + "SqlAOP": { + "Enabled": true, + "LogToFile": { + "Enabled": false + }, + "LogToDB": { + "Enabled": false + }, + "LogToConsole": { + "Enabled": true + } + }, + "Date": "2018-08-28", + "SeedDBEnabled": true, //只生成表结构 + "SeedDBDataEnabled": true, //生成表,并初始化数据 + "Author": "Blog.Core", + "SvcName": "", // /svc/blog + "UseLoadTest": false + } +} diff --git a/Blog.Core.Api/CustomConfig/Audience.json b/Blog.Core.Api/CustomConfig/Audience.json new file mode 100644 index 00000000..f104c6f9 --- /dev/null +++ b/Blog.Core.Api/CustomConfig/Audience.json @@ -0,0 +1,8 @@ +{ + "Audience": { + "Secret": "sdfsdfsrty45634kkhllghtdgdfss345t678fs", //不要太短,16位+ + "SecretFile": "C:\\my-file\\blog.core.audience.secret.txt", //安全。内容就是Secret + "Issuer": "Blog.Core", + "Audience": "wr" + } +} diff --git a/Blog.Core.Api/CustomConfig/ConsulSetting.json b/Blog.Core.Api/CustomConfig/ConsulSetting.json new file mode 100644 index 00000000..9c65d8ef --- /dev/null +++ b/Blog.Core.Api/CustomConfig/ConsulSetting.json @@ -0,0 +1,9 @@ +{ + "ConsulSetting": { + "ServiceName": "BlogCoreService", + "ServiceIP": "localhost", + "ServicePort": "9291", + "ServiceHealthCheck": "/healthcheck", + "ConsulAddress": "http://localhost:8500" + } +} diff --git a/Blog.Core.Api/CustomConfig/Db.json b/Blog.Core.Api/CustomConfig/Db.json new file mode 100644 index 00000000..2c2935b5 --- /dev/null +++ b/Blog.Core.Api/CustomConfig/Db.json @@ -0,0 +1,80 @@ +{ + // 请配置MainDB为你想要的主库的ConnId值,并设置对应的Enabled为true; + // *** 单库操作,把 MutiDBEnabled 设为false ***; + // *** 多库操作,把 MutiDBEnabled 设为true,其他的从库Enabled也为true **; + // 具体配置看视频:https://www.bilibili.com/video/BV1BJ411B7mn?p=6 + + "MainDB": "WMBLOG_SQLITE", //当前项目的主库,所对应的连接字符串的Enabled必须为true + "MutiDBEnabled": false, //是否开启多库模式 + "CQRSEnabled": false, //是否开启读写分离模式,必须是单库模式,且数据库类型一致,比如都是SqlServer + "DBS": [ + /* + 对应下边的 DBType + MySql = 0, + SqlServer = 1, + Sqlite = 2, + Oracle = 3, + PostgreSQL = 4, + Dm = 5,//达梦 + Kdbndp = 6,//人大金仓 + */ + { + "ConnId": "WMBLOG_SQLITE", + "DBType": 2, + "Enabled": true, + "HitRate": 50, // 值越大,优先级越高 + "Connection": "WMBlog.db" //sqlite只写数据库名就行 + }, + { + "ConnId": "WMBLOG_MSSQL_1", + "DBType": 1, + "Enabled": false, + "HitRate": 40, + "Connection": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=WMBLOG_MSSQL_1;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False", + "ProviderName": "System.Data.SqlClient" + }, + { + "ConnId": "WMBLOG_MSSQL_2", + "DBType": 1, + "Enabled": false, + "HitRate": 30, + "Connection": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=WMBLOG_MSSQL_2;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False", + "ProviderName": "System.Data.SqlClient" + }, + { + "ConnId": "WMBLOG_MYSQL", + "DBType": 0, + "Enabled": false, + "HitRate": 20, + "Connection": "server=.;Database=ddd;Uid=root;Pwd=123456;Port=10060;Allow User Variables=True;" + }, + { + "ConnId": "WMBLOG_MYSQL_2", + "DBType": 0, + "Enabled": true, + "HitRate": 20, + "Connection": "server=localhost;Database=blogcore001;Uid=root;Pwd=root;Port=3306;Allow User Variables=True;" + }, + { + "ConnId": "WMBLOG_ORACLE", + "DBType": 3, + "Enabled": false, + "HitRate": 10, + "Connection": "Data Source=127.0.0.1/ops;User ID=OPS;Password=123456;Persist Security Info=True;Connection Timeout=60;" + }, + { + "ConnId": "WMBLOG_DM", + "DBType": 5, + "Enabled": false, + "HitRate": 10, + "Connection": "PORT=5236;DATABASE=DAMENG;HOST=localhost;PASSWORD=SYSDBA;USER ID=SYSDBA;" + }, + { + "ConnId": "WMBLOG_KDBNDP", + "DBType": 6, + "Enabled": true, + "HitRate": 10, + "Connection": "Server=127.0.0.1;Port=54321;UID=SYSTEM;PWD=system;database=SQLSUGAR4XTEST1;" + } + ] +} diff --git a/Blog.Core.Api/CustomConfig/EventBus.json b/Blog.Core.Api/CustomConfig/EventBus.json new file mode 100644 index 00000000..4f4589f8 --- /dev/null +++ b/Blog.Core.Api/CustomConfig/EventBus.json @@ -0,0 +1,6 @@ +{ + "EventBus": { + "Enabled": false, + "SubscriptionClientName": "Blog.Core" + } +} diff --git a/Blog.Core.Api/CustomConfig/IpRateLimiting.json b/Blog.Core.Api/CustomConfig/IpRateLimiting.json new file mode 100644 index 00000000..9ca9f535 --- /dev/null +++ b/Blog.Core.Api/CustomConfig/IpRateLimiting.json @@ -0,0 +1,40 @@ +{ + "IpRateLimiting": { + "EnableEndpointRateLimiting": true, //False: globally executed, true: executed for each + "StackBlockedRequests": false, //False: Number of rejections should be recorded on another counter + "RealIpHeader": "X-Real-IP", + "ClientIdHeader": "X-ClientId", + "IpWhitelist": [], //白名单 + "EndpointWhitelist": [ "get:/api/xxx", "*:/api/yyy" ], + "ClientWhitelist": [ "dev-client-1", "dev-client-2" ], + "QuotaExceededResponse": { + "Content": "{{\"status\":429,\"msg\":\"访问过于频繁,请稍后重试\",\"success\":false}}", + "ContentType": "application/json", + "StatusCode": 429 + }, + "HttpStatusCode": 429, //返回状态码 + "GeneralRules": [ //api规则,结尾一定要带* + { + "Endpoint": "*:/api/blog*", + "Period": "1m", + "Limit": 20 + }, + { + "Endpoint": "*/api/*", + "Period": "1s", + "Limit": 3 + }, + { + "Endpoint": "*/api/*", + "Period": "1m", + "Limit": 30 + }, + { + "Endpoint": "*/api/*", + "Period": "12h", + "Limit": 500 + } + ] + + } +} diff --git a/Blog.Core.Api/CustomConfig/Kafka.json b/Blog.Core.Api/CustomConfig/Kafka.json new file mode 100644 index 00000000..a7ddcaac --- /dev/null +++ b/Blog.Core.Api/CustomConfig/Kafka.json @@ -0,0 +1,9 @@ +{ + "Kafka": { + "Enabled": false, + "Servers": "localhost:9092", + "Topic": "blog", + "GroupId": "blog-consumer", + "NumPartitions": 3 //主题分区数量 + } +} diff --git a/Blog.Core.Api/CustomConfig/LogFiedOutPut.json b/Blog.Core.Api/CustomConfig/LogFiedOutPut.json new file mode 100644 index 00000000..32182dd1 --- /dev/null +++ b/Blog.Core.Api/CustomConfig/LogFiedOutPut.json @@ -0,0 +1,12 @@ +{ + "LogFiedOutPutConfigs": { + "tcpAddressHost": "", // 输出elk的tcp连接地址 + "tcpAddressPort": 0, // 输出elk的tcp端口号 + "ConfigsInfo": [ // 配置的输出elk节点内容 常用语动态标识 + { + "FiedName": "applicationName", + "FiedValue": "Blog.Core.Api" + } + ] + } +} diff --git a/Blog.Core.Api/CustomConfig/Middleware.json b/Blog.Core.Api/CustomConfig/Middleware.json new file mode 100644 index 00000000..b211f54d --- /dev/null +++ b/Blog.Core.Api/CustomConfig/Middleware.json @@ -0,0 +1,47 @@ +{ + "Middleware": { + "RequestResponseLog": { + "Enabled": true, + "LogToFile": { + "Enabled": false + }, + "LogToDB": { + "Enabled": true + } + }, + "IPLog": { + "Enabled": true, + "LogToFile": { + "Enabled": false + }, + "LogToDB": { + "Enabled": true + } + }, + "RecordAccessLogs": { + "Enabled": true, + "LogToFile": { + "Enabled": false + }, + "LogToDB": { + "Enabled": true + }, + "IgnoreApis": "/api/permission/getnavigationbar,/api/monitor/getids4users,/api/monitor/getaccesslogs,/api/monitor/server,/api/monitor/getactiveusers,/api/monitor/server," + }, + "SignalR": { + "Enabled": false + }, + "SignalRSendLog": { + "Enabled": false + }, + "QuartzNetJob": { + "Enabled": true + }, + "Consul": { + "Enabled": false + }, + "IpRateLimit": { + "Enabled": true + } + } +} diff --git a/Blog.Core.Api/CustomConfig/Mongo.json b/Blog.Core.Api/CustomConfig/Mongo.json new file mode 100644 index 00000000..60b11e95 --- /dev/null +++ b/Blog.Core.Api/CustomConfig/Mongo.json @@ -0,0 +1,6 @@ +{ + "Mongo": { + "ConnectionString": "mongodb://nosql.data", + "Database": "BlogCoreDb" + } +} diff --git a/Blog.Core.Api/CustomConfig/Nacos.json b/Blog.Core.Api/CustomConfig/Nacos.json new file mode 100644 index 00000000..a369d76b --- /dev/null +++ b/Blog.Core.Api/CustomConfig/Nacos.json @@ -0,0 +1,11 @@ +{ + "nacos": { + "ServerAddresses": [ "http://localhost:8848" ], // nacos 连接地址 + "DefaultTimeOut": 15000, // 默认超时时间 + "Namespace": "public", // 命名空间 + "ListenInterval": 10000, // 监听的频率 + "ServiceName": "blog.Core.Api", // 服务名 + "Port": "9291", // 服务端口号 + "RegisterEnabled": true // 是否直接注册nacos + } +} \ No newline at end of file diff --git a/Blog.Core.Api/CustomConfig/Pay.json b/Blog.Core.Api/CustomConfig/Pay.json new file mode 100644 index 00000000..fd4e77e6 --- /dev/null +++ b/Blog.Core.Api/CustomConfig/Pay.json @@ -0,0 +1,11 @@ +{ + "PayInfo": { //建行聚合支付信息 + "MERCHANTID": "", //商户号 + "POSID": "", //柜台号 + "BRANCHID": "", //分行号 + "pubKey": "", //公钥 + "USER_ID": "", //操作员号 + "PASSWORD": "", //密码 + "OutAddress": "http://127.0.0.1:12345" //外联地址 + } +} diff --git a/Blog.Core.Api/CustomConfig/RabbitMQ.json b/Blog.Core.Api/CustomConfig/RabbitMQ.json new file mode 100644 index 00000000..7b77640a --- /dev/null +++ b/Blog.Core.Api/CustomConfig/RabbitMQ.json @@ -0,0 +1,9 @@ +{ + "RabbitMQ": { + "Enabled": false, + "Connection": "118.25.251.13", + "UserName": "", + "Password": "!", + "RetryCount": 3 + } +} diff --git a/Blog.Core.Api/CustomConfig/Redis.json b/Blog.Core.Api/CustomConfig/Redis.json new file mode 100644 index 00000000..224f3140 --- /dev/null +++ b/Blog.Core.Api/CustomConfig/Redis.json @@ -0,0 +1,5 @@ +{ + "Redis": { + "ConnectionString": "127.0.0.1:6319,password=admin" + } +} diff --git a/Blog.Core.Api/CustomConfig/Startup.json b/Blog.Core.Api/CustomConfig/Startup.json new file mode 100644 index 00000000..3f1c3e2f --- /dev/null +++ b/Blog.Core.Api/CustomConfig/Startup.json @@ -0,0 +1,36 @@ +{ + "Startup": { + "Domain": "http://localhost:9291", + "Cors": { + "PolicyName": "CorsIpAccess", //策略名称 + "EnableAllIPs": false, //当为true时,开放所有IP均可访问。 + // 支持多个域名端口,注意端口号后不要带/斜杆:比如localhost:8000/,是错的 + // 注意,http://127.0.0.1:1818 和 http://localhost:1818 是不一样的 + "IPs": "http://127.0.0.1:2364,http://localhost:2364,http://127.0.0.1:6688,http://localhost:6688" + }, + "AppConfigAlert": { + "Enabled": true + }, + "ApiName": "Blog.Core", + "IdentityServer4": { + "Enabled": false, // 这里默认是false,表示使用jwt,如果设置为true,则表示系统使用Ids4模式 + "AuthorizationUrl": "http://localhost:5004", // 认证中心域名 + "ApiName": "blog.core.api" // 资源服务器 + }, + "Authing": { + "Enabled": false, + "Issuer": "https://uldr24esx31h-demo.authing.cn/oidc", + "Audience": "63d51c4205c2849803be5178", + "JwksUri": "https://uldr24esx31h-demo.authing.cn/oidc/.well-known/jwks.json" + }, + "RedisMq": { + "Enabled": false //redis 消息队列 + }, + "MiniProfiler": { + "Enabled": false //性能分析开启 + }, + "Nacos": { + "Enabled": false //Nacos注册中心 + } + } +} diff --git a/Blog.Core.Api/DevelopmentCustomConfig/Apollo.json b/Blog.Core.Api/DevelopmentCustomConfig/Apollo.json new file mode 100644 index 00000000..0ca96f5b --- /dev/null +++ b/Blog.Core.Api/DevelopmentCustomConfig/Apollo.json @@ -0,0 +1,18 @@ +{ + //apollo 配置 + "Apollo": { + "Enable": false, + "Config": { + "AppId": "blog.core", + "Env": "DEV", + "MetaServer": "http://localhost:8080/", + "ConfigServer": [ "http://localhost:8080/" ] + }, + "Namespaces": [ //Namespaces的数据格式Properties,Xml,Json,Yml,Yaml,Txt + { + "Name": "test", + "Format": "json" + } + ] + } +} \ No newline at end of file diff --git a/Blog.Core.Api/DevelopmentCustomConfig/AppSettings.json b/Blog.Core.Api/DevelopmentCustomConfig/AppSettings.json new file mode 100644 index 00000000..a9f746b1 --- /dev/null +++ b/Blog.Core.Api/DevelopmentCustomConfig/AppSettings.json @@ -0,0 +1,40 @@ +{ + "AppSettings": { + "RedisCachingAOP": { + "Enabled": false + }, + "MemoryCachingAOP": { + "Enabled": true + }, + "LogAOP": { + "Enabled": true, + "LogToFile": { + "Enabled": false + }, + "LogToDB": { + "Enabled": true + } + }, + "TranAOP": { + "Enabled": true + }, + "SqlAOP": { + "Enabled": true, + "LogToFile": { + "Enabled": false + }, + "LogToDB": { + "Enabled": false + }, + "LogToConsole": { + "Enabled": true + } + }, + "Date": "2018-08-28", + "SeedDBEnabled": true, //只生成表结构 + "SeedDBDataEnabled": true, //生成表,并初始化数据 + "Author": "Blog.Core", + "SvcName": "", // /svc/blog + "UseLoadTest": false + } +} diff --git a/Blog.Core.Api/DevelopmentCustomConfig/Audience.json b/Blog.Core.Api/DevelopmentCustomConfig/Audience.json new file mode 100644 index 00000000..f104c6f9 --- /dev/null +++ b/Blog.Core.Api/DevelopmentCustomConfig/Audience.json @@ -0,0 +1,8 @@ +{ + "Audience": { + "Secret": "sdfsdfsrty45634kkhllghtdgdfss345t678fs", //不要太短,16位+ + "SecretFile": "C:\\my-file\\blog.core.audience.secret.txt", //安全。内容就是Secret + "Issuer": "Blog.Core", + "Audience": "wr" + } +} diff --git a/Blog.Core.Api/DevelopmentCustomConfig/ConsulSetting.json b/Blog.Core.Api/DevelopmentCustomConfig/ConsulSetting.json new file mode 100644 index 00000000..9c65d8ef --- /dev/null +++ b/Blog.Core.Api/DevelopmentCustomConfig/ConsulSetting.json @@ -0,0 +1,9 @@ +{ + "ConsulSetting": { + "ServiceName": "BlogCoreService", + "ServiceIP": "localhost", + "ServicePort": "9291", + "ServiceHealthCheck": "/healthcheck", + "ConsulAddress": "http://localhost:8500" + } +} diff --git a/Blog.Core.Api/DevelopmentCustomConfig/Db.json b/Blog.Core.Api/DevelopmentCustomConfig/Db.json new file mode 100644 index 00000000..2c2935b5 --- /dev/null +++ b/Blog.Core.Api/DevelopmentCustomConfig/Db.json @@ -0,0 +1,80 @@ +{ + // 请配置MainDB为你想要的主库的ConnId值,并设置对应的Enabled为true; + // *** 单库操作,把 MutiDBEnabled 设为false ***; + // *** 多库操作,把 MutiDBEnabled 设为true,其他的从库Enabled也为true **; + // 具体配置看视频:https://www.bilibili.com/video/BV1BJ411B7mn?p=6 + + "MainDB": "WMBLOG_SQLITE", //当前项目的主库,所对应的连接字符串的Enabled必须为true + "MutiDBEnabled": false, //是否开启多库模式 + "CQRSEnabled": false, //是否开启读写分离模式,必须是单库模式,且数据库类型一致,比如都是SqlServer + "DBS": [ + /* + 对应下边的 DBType + MySql = 0, + SqlServer = 1, + Sqlite = 2, + Oracle = 3, + PostgreSQL = 4, + Dm = 5,//达梦 + Kdbndp = 6,//人大金仓 + */ + { + "ConnId": "WMBLOG_SQLITE", + "DBType": 2, + "Enabled": true, + "HitRate": 50, // 值越大,优先级越高 + "Connection": "WMBlog.db" //sqlite只写数据库名就行 + }, + { + "ConnId": "WMBLOG_MSSQL_1", + "DBType": 1, + "Enabled": false, + "HitRate": 40, + "Connection": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=WMBLOG_MSSQL_1;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False", + "ProviderName": "System.Data.SqlClient" + }, + { + "ConnId": "WMBLOG_MSSQL_2", + "DBType": 1, + "Enabled": false, + "HitRate": 30, + "Connection": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=WMBLOG_MSSQL_2;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False", + "ProviderName": "System.Data.SqlClient" + }, + { + "ConnId": "WMBLOG_MYSQL", + "DBType": 0, + "Enabled": false, + "HitRate": 20, + "Connection": "server=.;Database=ddd;Uid=root;Pwd=123456;Port=10060;Allow User Variables=True;" + }, + { + "ConnId": "WMBLOG_MYSQL_2", + "DBType": 0, + "Enabled": true, + "HitRate": 20, + "Connection": "server=localhost;Database=blogcore001;Uid=root;Pwd=root;Port=3306;Allow User Variables=True;" + }, + { + "ConnId": "WMBLOG_ORACLE", + "DBType": 3, + "Enabled": false, + "HitRate": 10, + "Connection": "Data Source=127.0.0.1/ops;User ID=OPS;Password=123456;Persist Security Info=True;Connection Timeout=60;" + }, + { + "ConnId": "WMBLOG_DM", + "DBType": 5, + "Enabled": false, + "HitRate": 10, + "Connection": "PORT=5236;DATABASE=DAMENG;HOST=localhost;PASSWORD=SYSDBA;USER ID=SYSDBA;" + }, + { + "ConnId": "WMBLOG_KDBNDP", + "DBType": 6, + "Enabled": true, + "HitRate": 10, + "Connection": "Server=127.0.0.1;Port=54321;UID=SYSTEM;PWD=system;database=SQLSUGAR4XTEST1;" + } + ] +} diff --git a/Blog.Core.Api/DevelopmentCustomConfig/EventBus.json b/Blog.Core.Api/DevelopmentCustomConfig/EventBus.json new file mode 100644 index 00000000..4f4589f8 --- /dev/null +++ b/Blog.Core.Api/DevelopmentCustomConfig/EventBus.json @@ -0,0 +1,6 @@ +{ + "EventBus": { + "Enabled": false, + "SubscriptionClientName": "Blog.Core" + } +} diff --git a/Blog.Core.Api/DevelopmentCustomConfig/IpRateLimiting.json b/Blog.Core.Api/DevelopmentCustomConfig/IpRateLimiting.json new file mode 100644 index 00000000..9ca9f535 --- /dev/null +++ b/Blog.Core.Api/DevelopmentCustomConfig/IpRateLimiting.json @@ -0,0 +1,40 @@ +{ + "IpRateLimiting": { + "EnableEndpointRateLimiting": true, //False: globally executed, true: executed for each + "StackBlockedRequests": false, //False: Number of rejections should be recorded on another counter + "RealIpHeader": "X-Real-IP", + "ClientIdHeader": "X-ClientId", + "IpWhitelist": [], //白名单 + "EndpointWhitelist": [ "get:/api/xxx", "*:/api/yyy" ], + "ClientWhitelist": [ "dev-client-1", "dev-client-2" ], + "QuotaExceededResponse": { + "Content": "{{\"status\":429,\"msg\":\"访问过于频繁,请稍后重试\",\"success\":false}}", + "ContentType": "application/json", + "StatusCode": 429 + }, + "HttpStatusCode": 429, //返回状态码 + "GeneralRules": [ //api规则,结尾一定要带* + { + "Endpoint": "*:/api/blog*", + "Period": "1m", + "Limit": 20 + }, + { + "Endpoint": "*/api/*", + "Period": "1s", + "Limit": 3 + }, + { + "Endpoint": "*/api/*", + "Period": "1m", + "Limit": 30 + }, + { + "Endpoint": "*/api/*", + "Period": "12h", + "Limit": 500 + } + ] + + } +} diff --git a/Blog.Core.Api/DevelopmentCustomConfig/Kafka.json b/Blog.Core.Api/DevelopmentCustomConfig/Kafka.json new file mode 100644 index 00000000..a7ddcaac --- /dev/null +++ b/Blog.Core.Api/DevelopmentCustomConfig/Kafka.json @@ -0,0 +1,9 @@ +{ + "Kafka": { + "Enabled": false, + "Servers": "localhost:9092", + "Topic": "blog", + "GroupId": "blog-consumer", + "NumPartitions": 3 //主题分区数量 + } +} diff --git a/Blog.Core.Api/DevelopmentCustomConfig/LogFiedOutPut.json b/Blog.Core.Api/DevelopmentCustomConfig/LogFiedOutPut.json new file mode 100644 index 00000000..32182dd1 --- /dev/null +++ b/Blog.Core.Api/DevelopmentCustomConfig/LogFiedOutPut.json @@ -0,0 +1,12 @@ +{ + "LogFiedOutPutConfigs": { + "tcpAddressHost": "", // 输出elk的tcp连接地址 + "tcpAddressPort": 0, // 输出elk的tcp端口号 + "ConfigsInfo": [ // 配置的输出elk节点内容 常用语动态标识 + { + "FiedName": "applicationName", + "FiedValue": "Blog.Core.Api" + } + ] + } +} diff --git a/Blog.Core.Api/DevelopmentCustomConfig/Middleware.json b/Blog.Core.Api/DevelopmentCustomConfig/Middleware.json new file mode 100644 index 00000000..b211f54d --- /dev/null +++ b/Blog.Core.Api/DevelopmentCustomConfig/Middleware.json @@ -0,0 +1,47 @@ +{ + "Middleware": { + "RequestResponseLog": { + "Enabled": true, + "LogToFile": { + "Enabled": false + }, + "LogToDB": { + "Enabled": true + } + }, + "IPLog": { + "Enabled": true, + "LogToFile": { + "Enabled": false + }, + "LogToDB": { + "Enabled": true + } + }, + "RecordAccessLogs": { + "Enabled": true, + "LogToFile": { + "Enabled": false + }, + "LogToDB": { + "Enabled": true + }, + "IgnoreApis": "/api/permission/getnavigationbar,/api/monitor/getids4users,/api/monitor/getaccesslogs,/api/monitor/server,/api/monitor/getactiveusers,/api/monitor/server," + }, + "SignalR": { + "Enabled": false + }, + "SignalRSendLog": { + "Enabled": false + }, + "QuartzNetJob": { + "Enabled": true + }, + "Consul": { + "Enabled": false + }, + "IpRateLimit": { + "Enabled": true + } + } +} diff --git a/Blog.Core.Api/DevelopmentCustomConfig/Mongo.json b/Blog.Core.Api/DevelopmentCustomConfig/Mongo.json new file mode 100644 index 00000000..60b11e95 --- /dev/null +++ b/Blog.Core.Api/DevelopmentCustomConfig/Mongo.json @@ -0,0 +1,6 @@ +{ + "Mongo": { + "ConnectionString": "mongodb://nosql.data", + "Database": "BlogCoreDb" + } +} diff --git a/Blog.Core.Api/DevelopmentCustomConfig/Nacos.json b/Blog.Core.Api/DevelopmentCustomConfig/Nacos.json new file mode 100644 index 00000000..a369d76b --- /dev/null +++ b/Blog.Core.Api/DevelopmentCustomConfig/Nacos.json @@ -0,0 +1,11 @@ +{ + "nacos": { + "ServerAddresses": [ "http://localhost:8848" ], // nacos 连接地址 + "DefaultTimeOut": 15000, // 默认超时时间 + "Namespace": "public", // 命名空间 + "ListenInterval": 10000, // 监听的频率 + "ServiceName": "blog.Core.Api", // 服务名 + "Port": "9291", // 服务端口号 + "RegisterEnabled": true // 是否直接注册nacos + } +} \ No newline at end of file diff --git a/Blog.Core.Api/DevelopmentCustomConfig/Pay.json b/Blog.Core.Api/DevelopmentCustomConfig/Pay.json new file mode 100644 index 00000000..fd4e77e6 --- /dev/null +++ b/Blog.Core.Api/DevelopmentCustomConfig/Pay.json @@ -0,0 +1,11 @@ +{ + "PayInfo": { //建行聚合支付信息 + "MERCHANTID": "", //商户号 + "POSID": "", //柜台号 + "BRANCHID": "", //分行号 + "pubKey": "", //公钥 + "USER_ID": "", //操作员号 + "PASSWORD": "", //密码 + "OutAddress": "http://127.0.0.1:12345" //外联地址 + } +} diff --git a/Blog.Core.Api/DevelopmentCustomConfig/RabbitMQ.json b/Blog.Core.Api/DevelopmentCustomConfig/RabbitMQ.json new file mode 100644 index 00000000..7b77640a --- /dev/null +++ b/Blog.Core.Api/DevelopmentCustomConfig/RabbitMQ.json @@ -0,0 +1,9 @@ +{ + "RabbitMQ": { + "Enabled": false, + "Connection": "118.25.251.13", + "UserName": "", + "Password": "!", + "RetryCount": 3 + } +} diff --git a/Blog.Core.Api/DevelopmentCustomConfig/Redis.json b/Blog.Core.Api/DevelopmentCustomConfig/Redis.json new file mode 100644 index 00000000..224f3140 --- /dev/null +++ b/Blog.Core.Api/DevelopmentCustomConfig/Redis.json @@ -0,0 +1,5 @@ +{ + "Redis": { + "ConnectionString": "127.0.0.1:6319,password=admin" + } +} diff --git a/Blog.Core.Api/DevelopmentCustomConfig/Startup.json b/Blog.Core.Api/DevelopmentCustomConfig/Startup.json new file mode 100644 index 00000000..3f1c3e2f --- /dev/null +++ b/Blog.Core.Api/DevelopmentCustomConfig/Startup.json @@ -0,0 +1,36 @@ +{ + "Startup": { + "Domain": "http://localhost:9291", + "Cors": { + "PolicyName": "CorsIpAccess", //策略名称 + "EnableAllIPs": false, //当为true时,开放所有IP均可访问。 + // 支持多个域名端口,注意端口号后不要带/斜杆:比如localhost:8000/,是错的 + // 注意,http://127.0.0.1:1818 和 http://localhost:1818 是不一样的 + "IPs": "http://127.0.0.1:2364,http://localhost:2364,http://127.0.0.1:6688,http://localhost:6688" + }, + "AppConfigAlert": { + "Enabled": true + }, + "ApiName": "Blog.Core", + "IdentityServer4": { + "Enabled": false, // 这里默认是false,表示使用jwt,如果设置为true,则表示系统使用Ids4模式 + "AuthorizationUrl": "http://localhost:5004", // 认证中心域名 + "ApiName": "blog.core.api" // 资源服务器 + }, + "Authing": { + "Enabled": false, + "Issuer": "https://uldr24esx31h-demo.authing.cn/oidc", + "Audience": "63d51c4205c2849803be5178", + "JwksUri": "https://uldr24esx31h-demo.authing.cn/oidc/.well-known/jwks.json" + }, + "RedisMq": { + "Enabled": false //redis 消息队列 + }, + "MiniProfiler": { + "Enabled": false //性能分析开启 + }, + "Nacos": { + "Enabled": false //Nacos注册中心 + } + } +} diff --git a/Blog.Core.Api/Program.cs b/Blog.Core.Api/Program.cs index f5223beb..f0ec67bf 100644 --- a/Blog.Core.Api/Program.cs +++ b/Blog.Core.Api/Program.cs @@ -40,15 +40,11 @@ builder.SetMinimumLevel(LogLevel.Error); builder.AddLog4Net(Path.Combine(Directory.GetCurrentDirectory(), "Log4net.config")); }) -.ConfigureAppConfiguration((hostingContext, config) => -{ - config.Sources.Clear(); - config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: false); - config.AddConfigurationApollo("appsettings.apollo.json"); -}); +.ConfigureAppConfiguration(AppSettings.AddConfigureFiles) +.ConfigureAppConfiguration(config=> config.AddConfigurationApollo()); // 2、配置服务 -builder.Services.AddSingleton(new AppSettings(builder.Configuration)); +// builder.Services.AddSingleton(new AppSettings(builder.Configuration)); builder.Services.AddSingleton(new LogLock(builder.Environment.ContentRootPath)); builder.Services.AddUiFilesZipSetup(builder.Environment); diff --git a/Blog.Core.Api/Properties/launchSettings.json b/Blog.Core.Api/Properties/launchSettings.json index 425ec45f..dc5b3c8c 100644 --- a/Blog.Core.Api/Properties/launchSettings.json +++ b/Blog.Core.Api/Properties/launchSettings.json @@ -1,4 +1,5 @@ { + "$schema": "http://json.schemastore.org/launchsettings.json", "iisSettings": { "windowsAuthentication": false, "anonymousAuthentication": true, @@ -7,7 +8,6 @@ "sslPort": 0 } }, - "$schema": "http://json.schemastore.org/launchsettings.json", "profiles": { "Blog.Core": { "commandName": "Project", diff --git a/Blog.Core.Api/Startup.cs b/Blog.Core.Api/Startup.cs index bc1630f1..718af7e0 100644 --- a/Blog.Core.Api/Startup.cs +++ b/Blog.Core.Api/Startup.cs @@ -38,7 +38,7 @@ public Startup(IConfiguration configuration, IWebHostEnvironment env) public void ConfigureServices(IServiceCollection services) { // 以下code可能与文章中不一样,对代码做了封装,具体查看右侧 Extensions 文件夹. - services.AddSingleton(new AppSettings(Configuration)); + // services.AddSingleton(new AppSettings(Configuration)); services.AddSingleton(new LogLock(Env.ContentRootPath)); services.AddUiFilesZipSetup(Env); diff --git a/Blog.Core.Api/appsettings.Development.json b/Blog.Core.Api/appsettings.Development.json index 9016c7ce..4002901e 100644 --- a/Blog.Core.Api/appsettings.Development.json +++ b/Blog.Core.Api/appsettings.Development.json @@ -1,11 +1,33 @@ { - "nacos": { - "ServerAddresses": [ "http://localhost:8848" ], // nacos 连接地址 - "DefaultTimeOut": 15000, // 默认超时时间 - "Namespace": "public", // 命名空间 - "ListenInterval": 10000, // 监听的频率 - "ServiceName": "blog.Core.Api", // 服务名 - "Port": "9291", // 服务端口号 - "RegisterEnabled": true // 是否直接注册nacos + "urls": "http://*:9291", //web服务端口,如果用IIS部署,把这个去掉 + "Logging": { + "LogLevel": { + "Default": "Information", //加入Default否则log4net本地写入不了日志 + "Blog.Core.AuthHelper.ApiResponseHandler": "Error" + }, + "IncludeScopes": false, + "Debug": { + "LogLevel": { + "Default": "Warning" + } + }, + "Console": { + "LogLevel": { + "Default": "Warning", + "Microsoft.Hosting.Lifetime": "Debug" + } + }, + "Log4Net": { + "Name": "Blog.Core" + } + }, + "AllowedHosts": "*", + + // 自定义配置信息 + "CustomConfigInfo": { + // 子文件目录集合 + "ConfigFileFolders": [ "DevelopmentCustomConfig" ], + // 要排除的文件名集合 + "ExcludeSubFiles": [] } -} \ No newline at end of file +} diff --git a/Blog.Core.Api/appsettings.backup.json b/Blog.Core.Api/appsettings.backup.json new file mode 100644 index 00000000..ea678174 --- /dev/null +++ b/Blog.Core.Api/appsettings.backup.json @@ -0,0 +1,326 @@ +{ + "urls": "http://*:9291", //web服务端口,如果用IIS部署,把这个去掉 + "Logging": { + "LogLevel": { + "Default": "Information", //加入Default否则log4net本地写入不了日志 + "Blog.Core.AuthHelper.ApiResponseHandler": "Error" + }, + "Debug": { + "IncludeScopes": false, + "LogLevel": { + "Default": "Warning" + } + }, + "Console": { + "IncludeScopes": false, + "LogLevel": { + "Default": "Warning", + "Microsoft.Hosting.Lifetime": "Debug" + } + }, + "Log4Net": { + "Name": "Blog.Core" + } + }, + "AllowedHosts": "*", + "Redis": { + "ConnectionString": "127.0.0.1:6319,password=admin" + }, + "RabbitMQ": { + "Enabled": false, + "Connection": "118.25.251.13", + "UserName": "", + "Password": "!", + "RetryCount": 3 + }, + "Kafka": { + "Enabled": false, + "Servers": "localhost:9092", + "Topic": "blog", + "GroupId": "blog-consumer", + "NumPartitions": 3 //主题分区数量 + }, + "EventBus": { + "Enabled": false, + "SubscriptionClientName": "Blog.Core" + }, + "AppSettings": { + "RedisCachingAOP": { + "Enabled": false + }, + "MemoryCachingAOP": { + "Enabled": true + }, + "LogAOP": { + "Enabled": true, + "LogToFile": { + "Enabled": false + }, + "LogToDB": { + "Enabled": true + } + }, + "TranAOP": { + "Enabled": true + }, + "SqlAOP": { + "Enabled": true, + "LogToFile": { + "Enabled": false + }, + "LogToDB": { + "Enabled": false + }, + "LogToConsole": { + "Enabled": true + } + }, + "Date": "2018-08-28", + "SeedDBEnabled": true, //只生成表结构 + "SeedDBDataEnabled": true, //生成表,并初始化数据 + "Author": "Blog.Core", + "SvcName": "", // /svc/blog + "UseLoadTest": false + }, + + // 请配置MainDB为你想要的主库的ConnId值,并设置对应的Enabled为true; + // *** 单库操作,把 MutiDBEnabled 设为false ***; + // *** 多库操作,把 MutiDBEnabled 设为true,其他的从库Enabled也为true **; + // 具体配置看视频:https://www.bilibili.com/video/BV1BJ411B7mn?p=6 + + "MainDB": "WMBLOG_SQLITE", //当前项目的主库,所对应的连接字符串的Enabled必须为true + "MutiDBEnabled": false, //是否开启多库模式 + "CQRSEnabled": false, //是否开启读写分离模式,必须是单库模式,且数据库类型一致,比如都是SqlServer + "DBS": [ + /* + 对应下边的 DBType + MySql = 0, + SqlServer = 1, + Sqlite = 2, + Oracle = 3, + PostgreSQL = 4, + Dm = 5,//达梦 + Kdbndp = 6,//人大金仓 + */ + { + "ConnId": "WMBLOG_SQLITE", + "DBType": 2, + "Enabled": true, + "HitRate": 50, // 值越大,优先级越高 + "Connection": "WMBlog.db" //sqlite只写数据库名就行 + }, + { + "ConnId": "WMBLOG_MSSQL_1", + "DBType": 1, + "Enabled": false, + "HitRate": 40, + "Connection": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=WMBLOG_MSSQL_1;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False", + "ProviderName": "System.Data.SqlClient" + }, + { + "ConnId": "WMBLOG_MSSQL_2", + "DBType": 1, + "Enabled": false, + "HitRate": 30, + "Connection": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=WMBLOG_MSSQL_2;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False", + "ProviderName": "System.Data.SqlClient" + }, + { + "ConnId": "WMBLOG_MYSQL", + "DBType": 0, + "Enabled": false, + "HitRate": 20, + "Connection": "server=.;Database=ddd;Uid=root;Pwd=123456;Port=10060;Allow User Variables=True;" + }, + { + "ConnId": "WMBLOG_MYSQL_2", + "DBType": 0, + "Enabled": true, + "HitRate": 20, + "Connection": "server=localhost;Database=blogcore001;Uid=root;Pwd=root;Port=3306;Allow User Variables=True;" + }, + { + "ConnId": "WMBLOG_ORACLE", + "DBType": 3, + "Enabled": false, + "HitRate": 10, + "Connection": "Data Source=127.0.0.1/ops;User ID=OPS;Password=123456;Persist Security Info=True;Connection Timeout=60;" + }, + { + "ConnId": "WMBLOG_DM", + "DBType": 5, + "Enabled": false, + "HitRate": 10, + "Connection": "PORT=5236;DATABASE=DAMENG;HOST=localhost;PASSWORD=SYSDBA;USER ID=SYSDBA;" + }, + { + "ConnId": "WMBLOG_KDBNDP", + "DBType": 6, + "Enabled": true, + "HitRate": 10, + "Connection": "Server=127.0.0.1;Port=54321;UID=SYSTEM;PWD=system;database=SQLSUGAR4XTEST1;" + } + ], + "Audience": { + "Secret": "sdfsdfsrty45634kkhllghtdgdfss345t678fs", //不要太短,16位+ + "SecretFile": "C:\\my-file\\blog.core.audience.secret.txt", //安全。内容就是Secret + "Issuer": "Blog.Core", + "Audience": "wr" + }, + "Mongo": { + "ConnectionString": "mongodb://nosql.data", + "Database": "BlogCoreDb" + }, + "Startup": { + "Domain": "http://localhost:9291", + "Cors": { + "PolicyName": "CorsIpAccess", //策略名称 + "EnableAllIPs": false, //当为true时,开放所有IP均可访问。 + // 支持多个域名端口,注意端口号后不要带/斜杆:比如localhost:8000/,是错的 + // 注意,http://127.0.0.1:1818 和 http://localhost:1818 是不一样的 + "IPs": "http://127.0.0.1:2364,http://localhost:2364,http://127.0.0.1:6688,http://localhost:6688" + }, + "AppConfigAlert": { + "Enabled": true + }, + "ApiName": "Blog.Core", + "IdentityServer4": { + "Enabled": false, // 这里默认是false,表示使用jwt,如果设置为true,则表示系统使用Ids4模式 + "AuthorizationUrl": "http://localhost:5004", // 认证中心域名 + "ApiName": "blog.core.api" // 资源服务器 + }, + "Authing": { + "Enabled": false, + "Issuer": "https://uldr24esx31h-demo.authing.cn/oidc", + "Audience": "63d51c4205c2849803be5178", + "JwksUri": "https://uldr24esx31h-demo.authing.cn/oidc/.well-known/jwks.json" + }, + "RedisMq": { + "Enabled": false //redis 消息队列 + }, + "MiniProfiler": { + "Enabled": false //性能分析开启 + }, + "Nacos": { + "Enabled": false //Nacos注册中心 + } + }, + "Middleware": { + "RequestResponseLog": { + "Enabled": true, + "LogToFile": { + "Enabled": false + }, + "LogToDB": { + "Enabled": true + } + }, + "IPLog": { + "Enabled": true, + "LogToFile": { + "Enabled": false + }, + "LogToDB": { + "Enabled": true + } + }, + "RecordAccessLogs": { + "Enabled": true, + "LogToFile": { + "Enabled": false + }, + "LogToDB": { + "Enabled": true + }, + "IgnoreApis": "/api/permission/getnavigationbar,/api/monitor/getids4users,/api/monitor/getaccesslogs,/api/monitor/server,/api/monitor/getactiveusers,/api/monitor/server," + }, + "SignalR": { + "Enabled": false + }, + "SignalRSendLog": { + "Enabled": false + }, + "QuartzNetJob": { + "Enabled": true + }, + "Consul": { + "Enabled": false + }, + "IpRateLimit": { + "Enabled": true + } + }, + "IpRateLimiting": { + "EnableEndpointRateLimiting": true, //False: globally executed, true: executed for each + "StackBlockedRequests": false, //False: Number of rejections should be recorded on another counter + "RealIpHeader": "X-Real-IP", + "ClientIdHeader": "X-ClientId", + "IpWhitelist": [], //白名单 + "EndpointWhitelist": [ "get:/api/xxx", "*:/api/yyy" ], + "ClientWhitelist": [ "dev-client-1", "dev-client-2" ], + "QuotaExceededResponse": { + "Content": "{{\"status\":429,\"msg\":\"访问过于频繁,请稍后重试\",\"success\":false}}", + "ContentType": "application/json", + "StatusCode": 429 + }, + "HttpStatusCode": 429, //返回状态码 + "GeneralRules": [ //api规则,结尾一定要带* + { + "Endpoint": "*:/api/blog*", + "Period": "1m", + "Limit": 20 + }, + { + "Endpoint": "*/api/*", + "Period": "1s", + "Limit": 3 + }, + { + "Endpoint": "*/api/*", + "Period": "1m", + "Limit": 30 + }, + { + "Endpoint": "*/api/*", + "Period": "12h", + "Limit": 500 + } + ] + + }, + "ConsulSetting": { + "ServiceName": "BlogCoreService", + "ServiceIP": "localhost", + "ServicePort": "9291", + "ServiceHealthCheck": "/healthcheck", + "ConsulAddress": "http://localhost:8500" + }, + "PayInfo": { //建行聚合支付信息 + "MERCHANTID": "", //商户号 + "POSID": "", //柜台号 + "BRANCHID": "", //分行号 + "pubKey": "", //公钥 + "USER_ID": "", //操作员号 + "PASSWORD": "", //密码 + "OutAddress": "http://127.0.0.1:12345" //外联地址 + }, + "nacos": { + "ServerAddresses": [ "http://localhost:8848" ], // nacos 连接地址 + "DefaultTimeOut": 15000, // 默认超时时间 + "Namespace": "public", // 命名空间 + "ListenInterval": 10000, // 监听的频率 + "ServiceName": "blog.Core.Api", // 服务名 + "Port": "9291", // 服务端口号 + "RegisterEnabled": true // 是否直接注册nacos + }, + "LogFiedOutPutConfigs": { + "tcpAddressHost": "", // 输出elk的tcp连接地址 + "tcpAddressPort": 0, // 输出elk的tcp端口号 + "ConfigsInfo": [ // 配置的输出elk节点内容 常用语动态标识 + { + "FiedName": "applicationName", + "FiedValue": "Blog.Core.Api" + } + ] + } +} diff --git a/Blog.Core.Api/appsettings.json b/Blog.Core.Api/appsettings.json index ea678174..862dde75 100644 --- a/Blog.Core.Api/appsettings.json +++ b/Blog.Core.Api/appsettings.json @@ -23,304 +23,12 @@ } }, "AllowedHosts": "*", - "Redis": { - "ConnectionString": "127.0.0.1:6319,password=admin" - }, - "RabbitMQ": { - "Enabled": false, - "Connection": "118.25.251.13", - "UserName": "", - "Password": "!", - "RetryCount": 3 - }, - "Kafka": { - "Enabled": false, - "Servers": "localhost:9092", - "Topic": "blog", - "GroupId": "blog-consumer", - "NumPartitions": 3 //主题分区数量 - }, - "EventBus": { - "Enabled": false, - "SubscriptionClientName": "Blog.Core" - }, - "AppSettings": { - "RedisCachingAOP": { - "Enabled": false - }, - "MemoryCachingAOP": { - "Enabled": true - }, - "LogAOP": { - "Enabled": true, - "LogToFile": { - "Enabled": false - }, - "LogToDB": { - "Enabled": true - } - }, - "TranAOP": { - "Enabled": true - }, - "SqlAOP": { - "Enabled": true, - "LogToFile": { - "Enabled": false - }, - "LogToDB": { - "Enabled": false - }, - "LogToConsole": { - "Enabled": true - } - }, - "Date": "2018-08-28", - "SeedDBEnabled": true, //只生成表结构 - "SeedDBDataEnabled": true, //生成表,并初始化数据 - "Author": "Blog.Core", - "SvcName": "", // /svc/blog - "UseLoadTest": false - }, - - // 请配置MainDB为你想要的主库的ConnId值,并设置对应的Enabled为true; - // *** 单库操作,把 MutiDBEnabled 设为false ***; - // *** 多库操作,把 MutiDBEnabled 设为true,其他的从库Enabled也为true **; - // 具体配置看视频:https://www.bilibili.com/video/BV1BJ411B7mn?p=6 - - "MainDB": "WMBLOG_SQLITE", //当前项目的主库,所对应的连接字符串的Enabled必须为true - "MutiDBEnabled": false, //是否开启多库模式 - "CQRSEnabled": false, //是否开启读写分离模式,必须是单库模式,且数据库类型一致,比如都是SqlServer - "DBS": [ - /* - 对应下边的 DBType - MySql = 0, - SqlServer = 1, - Sqlite = 2, - Oracle = 3, - PostgreSQL = 4, - Dm = 5,//达梦 - Kdbndp = 6,//人大金仓 - */ - { - "ConnId": "WMBLOG_SQLITE", - "DBType": 2, - "Enabled": true, - "HitRate": 50, // 值越大,优先级越高 - "Connection": "WMBlog.db" //sqlite只写数据库名就行 - }, - { - "ConnId": "WMBLOG_MSSQL_1", - "DBType": 1, - "Enabled": false, - "HitRate": 40, - "Connection": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=WMBLOG_MSSQL_1;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False", - "ProviderName": "System.Data.SqlClient" - }, - { - "ConnId": "WMBLOG_MSSQL_2", - "DBType": 1, - "Enabled": false, - "HitRate": 30, - "Connection": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=WMBLOG_MSSQL_2;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False", - "ProviderName": "System.Data.SqlClient" - }, - { - "ConnId": "WMBLOG_MYSQL", - "DBType": 0, - "Enabled": false, - "HitRate": 20, - "Connection": "server=.;Database=ddd;Uid=root;Pwd=123456;Port=10060;Allow User Variables=True;" - }, - { - "ConnId": "WMBLOG_MYSQL_2", - "DBType": 0, - "Enabled": true, - "HitRate": 20, - "Connection": "server=localhost;Database=blogcore001;Uid=root;Pwd=root;Port=3306;Allow User Variables=True;" - }, - { - "ConnId": "WMBLOG_ORACLE", - "DBType": 3, - "Enabled": false, - "HitRate": 10, - "Connection": "Data Source=127.0.0.1/ops;User ID=OPS;Password=123456;Persist Security Info=True;Connection Timeout=60;" - }, - { - "ConnId": "WMBLOG_DM", - "DBType": 5, - "Enabled": false, - "HitRate": 10, - "Connection": "PORT=5236;DATABASE=DAMENG;HOST=localhost;PASSWORD=SYSDBA;USER ID=SYSDBA;" - }, - { - "ConnId": "WMBLOG_KDBNDP", - "DBType": 6, - "Enabled": true, - "HitRate": 10, - "Connection": "Server=127.0.0.1;Port=54321;UID=SYSTEM;PWD=system;database=SQLSUGAR4XTEST1;" - } - ], - "Audience": { - "Secret": "sdfsdfsrty45634kkhllghtdgdfss345t678fs", //不要太短,16位+ - "SecretFile": "C:\\my-file\\blog.core.audience.secret.txt", //安全。内容就是Secret - "Issuer": "Blog.Core", - "Audience": "wr" - }, - "Mongo": { - "ConnectionString": "mongodb://nosql.data", - "Database": "BlogCoreDb" - }, - "Startup": { - "Domain": "http://localhost:9291", - "Cors": { - "PolicyName": "CorsIpAccess", //策略名称 - "EnableAllIPs": false, //当为true时,开放所有IP均可访问。 - // 支持多个域名端口,注意端口号后不要带/斜杆:比如localhost:8000/,是错的 - // 注意,http://127.0.0.1:1818 和 http://localhost:1818 是不一样的 - "IPs": "http://127.0.0.1:2364,http://localhost:2364,http://127.0.0.1:6688,http://localhost:6688" - }, - "AppConfigAlert": { - "Enabled": true - }, - "ApiName": "Blog.Core", - "IdentityServer4": { - "Enabled": false, // 这里默认是false,表示使用jwt,如果设置为true,则表示系统使用Ids4模式 - "AuthorizationUrl": "http://localhost:5004", // 认证中心域名 - "ApiName": "blog.core.api" // 资源服务器 - }, - "Authing": { - "Enabled": false, - "Issuer": "https://uldr24esx31h-demo.authing.cn/oidc", - "Audience": "63d51c4205c2849803be5178", - "JwksUri": "https://uldr24esx31h-demo.authing.cn/oidc/.well-known/jwks.json" - }, - "RedisMq": { - "Enabled": false //redis 消息队列 - }, - "MiniProfiler": { - "Enabled": false //性能分析开启 - }, - "Nacos": { - "Enabled": false //Nacos注册中心 - } - }, - "Middleware": { - "RequestResponseLog": { - "Enabled": true, - "LogToFile": { - "Enabled": false - }, - "LogToDB": { - "Enabled": true - } - }, - "IPLog": { - "Enabled": true, - "LogToFile": { - "Enabled": false - }, - "LogToDB": { - "Enabled": true - } - }, - "RecordAccessLogs": { - "Enabled": true, - "LogToFile": { - "Enabled": false - }, - "LogToDB": { - "Enabled": true - }, - "IgnoreApis": "/api/permission/getnavigationbar,/api/monitor/getids4users,/api/monitor/getaccesslogs,/api/monitor/server,/api/monitor/getactiveusers,/api/monitor/server," - }, - "SignalR": { - "Enabled": false - }, - "SignalRSendLog": { - "Enabled": false - }, - "QuartzNetJob": { - "Enabled": true - }, - "Consul": { - "Enabled": false - }, - "IpRateLimit": { - "Enabled": true - } - }, - "IpRateLimiting": { - "EnableEndpointRateLimiting": true, //False: globally executed, true: executed for each - "StackBlockedRequests": false, //False: Number of rejections should be recorded on another counter - "RealIpHeader": "X-Real-IP", - "ClientIdHeader": "X-ClientId", - "IpWhitelist": [], //白名单 - "EndpointWhitelist": [ "get:/api/xxx", "*:/api/yyy" ], - "ClientWhitelist": [ "dev-client-1", "dev-client-2" ], - "QuotaExceededResponse": { - "Content": "{{\"status\":429,\"msg\":\"访问过于频繁,请稍后重试\",\"success\":false}}", - "ContentType": "application/json", - "StatusCode": 429 - }, - "HttpStatusCode": 429, //返回状态码 - "GeneralRules": [ //api规则,结尾一定要带* - { - "Endpoint": "*:/api/blog*", - "Period": "1m", - "Limit": 20 - }, - { - "Endpoint": "*/api/*", - "Period": "1s", - "Limit": 3 - }, - { - "Endpoint": "*/api/*", - "Period": "1m", - "Limit": 30 - }, - { - "Endpoint": "*/api/*", - "Period": "12h", - "Limit": 500 - } - ] - }, - "ConsulSetting": { - "ServiceName": "BlogCoreService", - "ServiceIP": "localhost", - "ServicePort": "9291", - "ServiceHealthCheck": "/healthcheck", - "ConsulAddress": "http://localhost:8500" - }, - "PayInfo": { //建行聚合支付信息 - "MERCHANTID": "", //商户号 - "POSID": "", //柜台号 - "BRANCHID": "", //分行号 - "pubKey": "", //公钥 - "USER_ID": "", //操作员号 - "PASSWORD": "", //密码 - "OutAddress": "http://127.0.0.1:12345" //外联地址 - }, - "nacos": { - "ServerAddresses": [ "http://localhost:8848" ], // nacos 连接地址 - "DefaultTimeOut": 15000, // 默认超时时间 - "Namespace": "public", // 命名空间 - "ListenInterval": 10000, // 监听的频率 - "ServiceName": "blog.Core.Api", // 服务名 - "Port": "9291", // 服务端口号 - "RegisterEnabled": true // 是否直接注册nacos - }, - "LogFiedOutPutConfigs": { - "tcpAddressHost": "", // 输出elk的tcp连接地址 - "tcpAddressPort": 0, // 输出elk的tcp端口号 - "ConfigsInfo": [ // 配置的输出elk节点内容 常用语动态标识 - { - "FiedName": "applicationName", - "FiedValue": "Blog.Core.Api" - } - ] + // 自定义配置信息 + "CustomConfigInfo": { + // 子文件目录集合 + "ConfigFileFolders": [ "CustomConfig" ], + // 要排除的文件名集合 + "ExcludeSubFiles": [ ] } } diff --git a/Blog.Core.Common/Blog.Core.Common.csproj b/Blog.Core.Common/Blog.Core.Common.csproj index fc0abb9d..1bc95aae 100644 --- a/Blog.Core.Common/Blog.Core.Common.csproj +++ b/Blog.Core.Common/Blog.Core.Common.csproj @@ -2,6 +2,7 @@ net6.0 + disable diff --git a/Blog.Core.Common/Helper/Appsettings.cs b/Blog.Core.Common/Helper/Appsettings.cs index d6d06651..3ab4e663 100644 --- a/Blog.Core.Common/Helper/Appsettings.cs +++ b/Blog.Core.Common/Helper/Appsettings.cs @@ -1,20 +1,22 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration.Json; +using Microsoft.Extensions.Hosting; using System; using System.Collections.Generic; +using System.IO; using System.Linq; namespace Blog.Core.Common { - /// - /// appsettings.json操作类 - /// - public class AppSettings + + public static class AppSettings { + /// + /// 配置 + /// public static IConfiguration Configuration { get; set; } - static string contentPath { get; set; } - public AppSettings(string contentPath) + public static void Init(string contentPath) { string Path = "appsettings.json"; @@ -27,16 +29,69 @@ public AppSettings(string contentPath) .Build(); } - public AppSettings(IConfiguration configuration) + + /// + /// 添加配置文件 + /// + /// + /// + public static void AddConfigureFiles(HostBuilderContext hostBuilder, IConfigurationBuilder builder) { - Configuration = configuration; + //清除原配置,添加默认配置 + builder.Sources.Clear(); + GetDefaultConfigFiles().ForEach(file => builder.AddJsonFile(Path.Combine(AppContext.BaseDirectory, file))); + Configuration = builder.Build(); + + /// + /// 获取默认配置文件 + /// + /// + static List GetDefaultConfigFiles() + { + List configFiles = new() { "appsettings.json" }; + string ASPNETCORE_ENVIRONMENT = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); + if (ASPNETCORE_ENVIRONMENT?.Length > 0) configFiles.Add($"appsettings.{ASPNETCORE_ENVIRONMENT}.json"); + return configFiles; + } } + + #region 获取配置信息 + + /// + /// 判断节点是否存在 + /// + /// 配置 + /// 节点路径 + /// 节点存在返回 true,否者 false + public static bool Exists(params string[] sections) => Configuration.Exists(sections); + + /// + /// 读取节点字符串 + /// + /// 配置 + /// 节点路径 + /// 和节点路径匹配的字符串 + public static string Get(params string[] sections) => Configuration.Get(sections); + + /// + /// 读取节点并转换成指定类型 + /// + /// 返回的类型 + /// 配置 + /// 节点路径 + /// 和节点路径匹配的T类型对象 + public static T Get(params string[] sections) => Configuration.Get(sections); + + #endregion 获取配置信息 + + #region 以前获取配置信息 /// /// 封装要操作的字符 /// /// 节点配置 /// + [Obsolete("推荐使用 Get 方法")] public static string app(params string[] sections) { try @@ -58,6 +113,7 @@ public static string app(params string[] sections) /// /// /// + [Obsolete("推荐使用 Get 方法")] public static List app(params string[] sections) { List list = new List(); @@ -72,6 +128,7 @@ public static List app(params string[] sections) /// /// /// + [Obsolete("推荐使用 Get 方法")] public static string GetValue(string sectionsPath) { try @@ -83,5 +140,40 @@ public static string GetValue(string sectionsPath) return ""; } + #endregion + } +} + +namespace Microsoft.Extensions.Configuration +{ + /// + /// (配置) 拓展 + /// + public static class IConfigurationExtensions + { + /// + /// 判断节点是否存在 + /// + /// 配置 + /// 节点路径 + /// 节点存在返回 true,否者 false + public static bool Exists(this IConfiguration configuration, params string[] sections) => configuration.GetSection(string.Join(':', sections)).Exists(); + + /// + /// 读取节点字符串 + /// + /// 配置 + /// 节点路径 + /// 和节点路径匹配的字符串 + public static string Get(this IConfiguration configuration, params string[] sections) => configuration[string.Join(':', sections)]; + + /// + /// 读取节点并转换成指定类型 + /// + /// 返回的类型 + /// 配置 + /// 节点路径 + /// 和节点路径匹配的T类型对象 + public static T Get(this IConfiguration configuration, params string[] sections) => configuration.GetSection(string.Join(':', sections)).Get(); } } diff --git a/Blog.Core.Extensions/Apollo/ConfigurationBuilderExtensions.cs b/Blog.Core.Extensions/Apollo/ConfigurationBuilderExtensions.cs index 909e9a19..6e832f36 100644 --- a/Blog.Core.Extensions/Apollo/ConfigurationBuilderExtensions.cs +++ b/Blog.Core.Extensions/Apollo/ConfigurationBuilderExtensions.cs @@ -7,6 +7,7 @@ using Com.Ctrip.Framework.Apollo.Logging; using Microsoft.Extensions.Primitives; using System.Reflection; +using Blog.Core.Common; namespace Blog.Core.Extensions.Apollo { @@ -17,7 +18,7 @@ public static class ConfigurationBuilderExtensions /// /// /// apollo配置文件路径 如果写入appsettings.json中 则jsonPath传null即可 - public static void AddConfigurationApollo(this IConfigurationBuilder builder,string jsonPath) + public static void AddConfigurationApollo(this IConfigurationBuilder builder,string jsonPath= null) { if (!string.IsNullOrEmpty(jsonPath)) { @@ -36,8 +37,9 @@ public static void AddConfigurationApollo(this IConfigurationBuilder builder,str { apolloBuilder.AddNamespace(item.Name, MatchConfigFileFormat(item.Format)); } + AppSettings.Configuration = builder.Build(); //监听apollo配置 - Monitor(builder.Build()); + Monitor((IConfigurationRoot)AppSettings.Configuration); } } diff --git a/Blog.Core.Extensions/ServiceExtensions/AppConfigSetup.cs b/Blog.Core.Extensions/ServiceExtensions/AppConfigSetup.cs index 0622e766..5cbf0448 100644 --- a/Blog.Core.Extensions/ServiceExtensions/AppConfigSetup.cs +++ b/Blog.Core.Extensions/ServiceExtensions/AppConfigSetup.cs @@ -1,6 +1,4 @@ using Blog.Core.Common; -using Blog.Core.Common.Helper; -using Blog.Core.Common.LogHelper; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; diff --git a/Blog.Core.Gateway/CustomConfig/ApiGateWay.json b/Blog.Core.Gateway/CustomConfig/ApiGateWay.json new file mode 100644 index 00000000..3fdd4e3e --- /dev/null +++ b/Blog.Core.Gateway/CustomConfig/ApiGateWay.json @@ -0,0 +1,11 @@ +{ + "ApiGateWay": { + "OcelotConfig": "OcelotConfig.json", + "OcelotConfigGroup": "DEFAULT_GROUP", + "AppConfig": "****.****.Gateway.json", + "AppConfigGroup": "DEFAULT_GROUP", + "PermissionServName": "****.****.Api", + "PermissionServGroup": "DEFAULT_GROUP", + "PermissionServUrl": "/api/Permission/GetPermissionlist" + } +} \ No newline at end of file diff --git a/Blog.Core.Gateway/CustomConfig/Audience.json b/Blog.Core.Gateway/CustomConfig/Audience.json new file mode 100644 index 00000000..da3b0b7b --- /dev/null +++ b/Blog.Core.Gateway/CustomConfig/Audience.json @@ -0,0 +1,8 @@ +{ + "Audience": { + "Secret": "sdfsdfsrty45634kkhllghtdgdfss345t678fs", + "SecretFile": "C:\\my-file\\blog.core.audience.secret.txt", + "Issuer": "Blog.Core", + "Audience": "wr" + } +} \ No newline at end of file diff --git a/Blog.Core.Gateway/CustomConfig/BlackList.json b/Blog.Core.Gateway/CustomConfig/BlackList.json new file mode 100644 index 00000000..e467c015 --- /dev/null +++ b/Blog.Core.Gateway/CustomConfig/BlackList.json @@ -0,0 +1,5 @@ +{ + "BlackList": [ + { "url": "/favicon.ico" } + ] +} \ No newline at end of file diff --git a/Blog.Core.Gateway/CustomConfig/Influxdb.json b/Blog.Core.Gateway/CustomConfig/Influxdb.json new file mode 100644 index 00000000..18cc201e --- /dev/null +++ b/Blog.Core.Gateway/CustomConfig/Influxdb.json @@ -0,0 +1,8 @@ +{ + "Influxdb": { + "Endpoint": "http://*******:9328", + "uid": "root", + "pwd": "*****", + "dbname": "mndata" + } +} \ No newline at end of file diff --git a/Blog.Core.Gateway/CustomConfig/Nacos.json b/Blog.Core.Gateway/CustomConfig/Nacos.json new file mode 100644 index 00000000..ce2afaf0 --- /dev/null +++ b/Blog.Core.Gateway/CustomConfig/Nacos.json @@ -0,0 +1,31 @@ +{ + "nacos": { + "ServerAddresses": [ "http://******:8848/" ], + "ServiceName": "*****.****.Gateway", + "DefaultTimeOut": 15000, + "Namespace": "****", + "ListenInterval": 1000, + "GroupName": "DEFAULT_GROUP", + "ClusterName": "DEFAULT", + "Ip": "", + "PreferredNetworks": "", + "Port": 8090, + "Weight": 100, + "RegisterEnabled": true, + "InstanceEnabled": true, + "Ephemeral": true, + "Secure": false, + "AccessKey": "", + "SecretKey": "", + "UserName": "****", + "Password": "*****", + "NamingUseRpc": true, + "NamingLoadCacheAtStart": "", + "LBStrategy": "WeightRandom", + "Metadata": { + "aa": "bb", + "cc": "dd", + "endpoint33": "******:8090" + } + } +} \ No newline at end of file diff --git a/Blog.Core.Gateway/ocelot.Development.json b/Blog.Core.Gateway/CustomConfig/Ocelot.json similarity index 100% rename from Blog.Core.Gateway/ocelot.Development.json rename to Blog.Core.Gateway/CustomConfig/Ocelot.json diff --git a/Blog.Core.Gateway/CustomConfig/Startup.json b/Blog.Core.Gateway/CustomConfig/Startup.json new file mode 100644 index 00000000..9a2ad0f6 --- /dev/null +++ b/Blog.Core.Gateway/CustomConfig/Startup.json @@ -0,0 +1,9 @@ +{ + "Startup": { + "Cors": { + "PolicyName": "CorsIpAccess", + "EnableAllIPs": false, + "IPs": "http://127.0.0.1:2364,http://localhost:2364" + } + } +} \ No newline at end of file diff --git a/Blog.Core.Gateway/CustomConfig/WhiteList.json b/Blog.Core.Gateway/CustomConfig/WhiteList.json new file mode 100644 index 00000000..afd00316 --- /dev/null +++ b/Blog.Core.Gateway/CustomConfig/WhiteList.json @@ -0,0 +1,8 @@ +{ + "WhiteList": [ + { "url": "/" }, + { "url": "/illagal/****" }, + { "url": "/api3/****" }, + { "url": "/baseapi/swagger.json" } + ] +} \ No newline at end of file diff --git a/Blog.Core.Gateway/CustomConfig/nacosConfig.json b/Blog.Core.Gateway/CustomConfig/nacosConfig.json new file mode 100644 index 00000000..26edf7a5 --- /dev/null +++ b/Blog.Core.Gateway/CustomConfig/nacosConfig.json @@ -0,0 +1,19 @@ +{ + "nacosConfig": { + "ServiceName": "*****.*****.Gateway", + "Optional": false, + "DataId": "options1", + "Tenant": "******", + "Group": "DEFAULT_GROUP", + "Namespace": "*****", + "ServerAddresses": [ "http://******:8848/" ], + "UserName": "****", + "Password": "*****", + "AccessKey": "", + "SecretKey": "", + "EndPoint": "", + "ConfigUseRpc": true, + "ConfigFilterAssemblies": [ "apigateway" ], + "ConfigFilterExtInfo": "{\"JsonPaths\":[\"ConnectionStrings.Default\"],\"Other\":\"xxxxxx\"}" + } +} \ No newline at end of file diff --git a/Blog.Core.Gateway/DevelopmentCustomConfig/ApiGateWay.json b/Blog.Core.Gateway/DevelopmentCustomConfig/ApiGateWay.json new file mode 100644 index 00000000..3fdd4e3e --- /dev/null +++ b/Blog.Core.Gateway/DevelopmentCustomConfig/ApiGateWay.json @@ -0,0 +1,11 @@ +{ + "ApiGateWay": { + "OcelotConfig": "OcelotConfig.json", + "OcelotConfigGroup": "DEFAULT_GROUP", + "AppConfig": "****.****.Gateway.json", + "AppConfigGroup": "DEFAULT_GROUP", + "PermissionServName": "****.****.Api", + "PermissionServGroup": "DEFAULT_GROUP", + "PermissionServUrl": "/api/Permission/GetPermissionlist" + } +} \ No newline at end of file diff --git a/Blog.Core.Gateway/DevelopmentCustomConfig/Audience.json b/Blog.Core.Gateway/DevelopmentCustomConfig/Audience.json new file mode 100644 index 00000000..da3b0b7b --- /dev/null +++ b/Blog.Core.Gateway/DevelopmentCustomConfig/Audience.json @@ -0,0 +1,8 @@ +{ + "Audience": { + "Secret": "sdfsdfsrty45634kkhllghtdgdfss345t678fs", + "SecretFile": "C:\\my-file\\blog.core.audience.secret.txt", + "Issuer": "Blog.Core", + "Audience": "wr" + } +} \ No newline at end of file diff --git a/Blog.Core.Gateway/DevelopmentCustomConfig/BlackList.json b/Blog.Core.Gateway/DevelopmentCustomConfig/BlackList.json new file mode 100644 index 00000000..e467c015 --- /dev/null +++ b/Blog.Core.Gateway/DevelopmentCustomConfig/BlackList.json @@ -0,0 +1,5 @@ +{ + "BlackList": [ + { "url": "/favicon.ico" } + ] +} \ No newline at end of file diff --git a/Blog.Core.Gateway/DevelopmentCustomConfig/Influxdb.json b/Blog.Core.Gateway/DevelopmentCustomConfig/Influxdb.json new file mode 100644 index 00000000..18cc201e --- /dev/null +++ b/Blog.Core.Gateway/DevelopmentCustomConfig/Influxdb.json @@ -0,0 +1,8 @@ +{ + "Influxdb": { + "Endpoint": "http://*******:9328", + "uid": "root", + "pwd": "*****", + "dbname": "mndata" + } +} \ No newline at end of file diff --git a/Blog.Core.Gateway/DevelopmentCustomConfig/Nacos.json b/Blog.Core.Gateway/DevelopmentCustomConfig/Nacos.json new file mode 100644 index 00000000..ce2afaf0 --- /dev/null +++ b/Blog.Core.Gateway/DevelopmentCustomConfig/Nacos.json @@ -0,0 +1,31 @@ +{ + "nacos": { + "ServerAddresses": [ "http://******:8848/" ], + "ServiceName": "*****.****.Gateway", + "DefaultTimeOut": 15000, + "Namespace": "****", + "ListenInterval": 1000, + "GroupName": "DEFAULT_GROUP", + "ClusterName": "DEFAULT", + "Ip": "", + "PreferredNetworks": "", + "Port": 8090, + "Weight": 100, + "RegisterEnabled": true, + "InstanceEnabled": true, + "Ephemeral": true, + "Secure": false, + "AccessKey": "", + "SecretKey": "", + "UserName": "****", + "Password": "*****", + "NamingUseRpc": true, + "NamingLoadCacheAtStart": "", + "LBStrategy": "WeightRandom", + "Metadata": { + "aa": "bb", + "cc": "dd", + "endpoint33": "******:8090" + } + } +} \ No newline at end of file diff --git a/Blog.Core.Gateway/DevelopmentCustomConfig/Ocelot.json b/Blog.Core.Gateway/DevelopmentCustomConfig/Ocelot.json new file mode 100644 index 00000000..6af5171b --- /dev/null +++ b/Blog.Core.Gateway/DevelopmentCustomConfig/Ocelot.json @@ -0,0 +1,59 @@ +{ + "Routes": [ + // blog-svc + { + "UpstreamPathTemplate": "/svc/blog/{url}", + "UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete" ], + "LoadBalancerOptions": { + "Type": "RoundRobin" + }, + "DownstreamPathTemplate": "/svc/blog/{url}", + "DownstreamScheme": "http", + "DownstreamHostAndPorts": [ + { + "Host": "localhost", + "Port": 9291 + } + ], + "AddHeadersToRequest": { + "user-phone": "Claims[user-phone] > value", + "gw-sign": "Claims[gw-sign] > value" + }, + "UpstreamHeaderTransform": { + "custom-key": "blog.gateway" + }, + "DownstreamHeaderTransform": { + "trace-id": "Trace-Id" + }, + "AuthenticationOptions": { + "AuthenticationProviderKey": "GW" + }, + "DelegatingHandlers": [ + "CustomResultHandler" + ] + }, + // blog-svc-swagger + { + "UpstreamPathTemplate": "/swagger/apiswg/blog-svc/swagger.json", + "UpstreamHttpMethod": [ "GET" ], + "DownstreamPathTemplate": "/swagger/V2/swagger.json", + "DownstreamScheme": "http", + "DownstreamHostAndPorts": [ + { + "Host": "localhost", + "Port": 9291 + } + ], + "LoadBalancer": "RoundRobin" + } + + ], + "GlobalConfiguration": { + "BaseUrl": "http://localhost:9000", + "ServiceDiscoveryProvider": { + "Host": "localhost", + "Port": 8500, + "Type": "Consul" + } + } +} \ No newline at end of file diff --git a/Blog.Core.Gateway/DevelopmentCustomConfig/Startup.json b/Blog.Core.Gateway/DevelopmentCustomConfig/Startup.json new file mode 100644 index 00000000..9a2ad0f6 --- /dev/null +++ b/Blog.Core.Gateway/DevelopmentCustomConfig/Startup.json @@ -0,0 +1,9 @@ +{ + "Startup": { + "Cors": { + "PolicyName": "CorsIpAccess", + "EnableAllIPs": false, + "IPs": "http://127.0.0.1:2364,http://localhost:2364" + } + } +} \ No newline at end of file diff --git a/Blog.Core.Gateway/DevelopmentCustomConfig/WhiteList.json b/Blog.Core.Gateway/DevelopmentCustomConfig/WhiteList.json new file mode 100644 index 00000000..afd00316 --- /dev/null +++ b/Blog.Core.Gateway/DevelopmentCustomConfig/WhiteList.json @@ -0,0 +1,8 @@ +{ + "WhiteList": [ + { "url": "/" }, + { "url": "/illagal/****" }, + { "url": "/api3/****" }, + { "url": "/baseapi/swagger.json" } + ] +} \ No newline at end of file diff --git a/Blog.Core.Gateway/DevelopmentCustomConfig/nacosConfig.json b/Blog.Core.Gateway/DevelopmentCustomConfig/nacosConfig.json new file mode 100644 index 00000000..26edf7a5 --- /dev/null +++ b/Blog.Core.Gateway/DevelopmentCustomConfig/nacosConfig.json @@ -0,0 +1,19 @@ +{ + "nacosConfig": { + "ServiceName": "*****.*****.Gateway", + "Optional": false, + "DataId": "options1", + "Tenant": "******", + "Group": "DEFAULT_GROUP", + "Namespace": "*****", + "ServerAddresses": [ "http://******:8848/" ], + "UserName": "****", + "Password": "*****", + "AccessKey": "", + "SecretKey": "", + "EndPoint": "", + "ConfigUseRpc": true, + "ConfigFilterAssemblies": [ "apigateway" ], + "ConfigFilterExtInfo": "{\"JsonPaths\":[\"ConnectionStrings.Default\"],\"Other\":\"xxxxxx\"}" + } +} \ No newline at end of file diff --git a/Blog.Core.Gateway/Helper/CustomJwtTokenAuthMiddleware.cs b/Blog.Core.Gateway/Helper/CustomJwtTokenAuthMiddleware.cs index 88181bc3..fc37e36b 100644 --- a/Blog.Core.Gateway/Helper/CustomJwtTokenAuthMiddleware.cs +++ b/Blog.Core.Gateway/Helper/CustomJwtTokenAuthMiddleware.cs @@ -35,7 +35,7 @@ public class CustomJwtTokenAuthMiddleware private readonly RequestDelegate _next; - public CustomJwtTokenAuthMiddleware(INacosNamingService serv, RequestDelegate next, IAuthenticationSchemeProvider schemes, AppSettings appset,ICaching cache) + public CustomJwtTokenAuthMiddleware(INacosNamingService serv, RequestDelegate next, IAuthenticationSchemeProvider schemes,ICaching cache) { NacosServClient = serv; _cache = cache; diff --git a/Blog.Core.Gateway/Program.cs b/Blog.Core.Gateway/Program.cs index 1ba46816..caf9a65b 100644 --- a/Blog.Core.Gateway/Program.cs +++ b/Blog.Core.Gateway/Program.cs @@ -1,5 +1,5 @@ +using Blog.Core.Common; using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; namespace Blog.Core.AdminMvc @@ -13,11 +13,7 @@ public static void Main(string[] args) public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) - .ConfigureAppConfiguration((hostingContext, config) => - { - config.AddJsonFile("ocelot.json", optional: true, reloadOnChange: true) - .AddJsonFile($"ocelot.{hostingContext.HostingEnvironment.EnvironmentName}.json", true, true); - }) + .ConfigureAppConfiguration(AppSettings.AddConfigureFiles) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup().UseUrls("http://*:9000"); diff --git a/Blog.Core.Gateway/Startup.cs b/Blog.Core.Gateway/Startup.cs index 552b4ef1..28fa822b 100644 --- a/Blog.Core.Gateway/Startup.cs +++ b/Blog.Core.Gateway/Startup.cs @@ -32,8 +32,6 @@ public Startup(IConfiguration configuration, IWebHostEnvironment env) // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { - services.AddSingleton(new AppSettings(Configuration)); - services.AddAuthentication_JWTSetup(); services.AddAuthentication() diff --git a/Blog.Core.Gateway/appsettings.Development.json b/Blog.Core.Gateway/appsettings.Development.json index 8983e0fc..c242ca5b 100644 --- a/Blog.Core.Gateway/appsettings.Development.json +++ b/Blog.Core.Gateway/appsettings.Development.json @@ -1,9 +1,15 @@ -{ +{ "Logging": { "LogLevel": { "Default": "Information", "Microsoft": "Warning", "Microsoft.Hosting.Lifetime": "Information" } + }, + + // 自定义配置信息 + "CustomConfigInfo": { + // 子文件目录集合 + "ConfigFileFolders": [ "DevelopmentCustomConfig" ] } } diff --git a/Blog.Core.Gateway/appsettings.Production.json b/Blog.Core.Gateway/appsettings.Production.json new file mode 100644 index 00000000..54fd3318 --- /dev/null +++ b/Blog.Core.Gateway/appsettings.Production.json @@ -0,0 +1,12 @@ +{ + // 自定义配置信息 + "CustomConfigInfo": { + /* + 自定义配置文件目录 + 目录支持程序根目录下和绝对路径 + 如果有多个相同路径的配置,后面将会覆盖前面的内容 + 建议测试类的配置文件夹路径写在后面 + */ + "ConfigFileFolders": [ "CustomConfig" ] + } +} diff --git a/Blog.Core.Gateway/appsettings.Staging.json b/Blog.Core.Gateway/appsettings.Staging.json new file mode 100644 index 00000000..54fd3318 --- /dev/null +++ b/Blog.Core.Gateway/appsettings.Staging.json @@ -0,0 +1,12 @@ +{ + // 自定义配置信息 + "CustomConfigInfo": { + /* + 自定义配置文件目录 + 目录支持程序根目录下和绝对路径 + 如果有多个相同路径的配置,后面将会覆盖前面的内容 + 建议测试类的配置文件夹路径写在后面 + */ + "ConfigFileFolders": [ "CustomConfig" ] + } +} diff --git a/Blog.Core.Gateway/appsettings.backup.json b/Blog.Core.Gateway/appsettings.backup.json new file mode 100644 index 00000000..c986b56c --- /dev/null +++ b/Blog.Core.Gateway/appsettings.backup.json @@ -0,0 +1,104 @@ +//appsettings 备份 +{ + "Logging": { + "IncludeScopes": false, + "Debug": { + "LogLevel": { + "Default": "Warning" + } + }, + "Console": { + "LogLevel": { + "Default": "Warning", + "Microsoft.Hosting.Lifetime": "Debug" + } + } + }, + "AllowedHosts": "*", + "Startup": { + "Cors": { + "PolicyName": "CorsIpAccess", + "EnableAllIPs": false, + "IPs": "http://127.0.0.1:2364,http://localhost:2364" + } + }, + "Audience": { + "Secret": "sdfsdfsrty45634kkhllghtdgdfss345t678fs", + "SecretFile": "C:\\my-file\\blog.core.audience.secret.txt", + "Issuer": "Blog.Core", + "Audience": "wr" + }, + "WhiteList": [ + { "url": "/" }, + { "url": "/illagal/****" }, + { "url": "/api3/****" }, + { "url": "/baseapi/swagger.json" } + ], + "BlackList": [ + { "url": "/favicon.ico" } + ], + "ApiGateWay": { + "OcelotConfig": "OcelotConfig.json", + "OcelotConfigGroup": "DEFAULT_GROUP", + "AppConfig": "****.****.Gateway.json", + "AppConfigGroup": "DEFAULT_GROUP", + "PermissionServName": "****.****.Api", + "PermissionServGroup": "DEFAULT_GROUP", + "PermissionServUrl": "/api/Permission/GetPermissionlist" + }, + "Influxdb": { + "Endpoint": "http://*******:9328", + "uid": "root", + "pwd": "*****", + "dbname": "mndata" + }, + "nacos": { + "ServerAddresses": [ "http://******:8848/" ], + "ServiceName": "*****.****.Gateway", + "DefaultTimeOut": 15000, + "Namespace": "****", + "ListenInterval": 1000, + "GroupName": "DEFAULT_GROUP", + "ClusterName": "DEFAULT", + "Ip": "", + "PreferredNetworks": "", + "Port": 8090, + "Weight": 100, + "RegisterEnabled": true, + "InstanceEnabled": true, + "Ephemeral": true, + "Secure": false, + "AccessKey": "", + "SecretKey": "", + "UserName": "****", + "Password": "*****", + "NamingUseRpc": true, + "NamingLoadCacheAtStart": "", + "LBStrategy": "WeightRandom", + "Metadata": { + "aa": "bb", + "cc": "dd", + "endpoint33": "******:8090" + } + }, + "nacosConfig": { + "ServiceName": "*****.*****.Gateway", + "Optional": false, + "DataId": "options1", + "Tenant": "******", + "Group": "DEFAULT_GROUP", + "Namespace": "*****", + "ServerAddresses": [ "http://******:8848/" ], + "UserName": "****", + "Password": "*****", + "AccessKey": "", + "SecretKey": "", + "EndPoint": "", + "ConfigUseRpc": true, + "ConfigFilterAssemblies": [ "apigateway" ], + "ConfigFilterExtInfo": "{\"JsonPaths\":[\"ConnectionStrings.Default\"],\"Other\":\"xxxxxx\"}" + } + + + +} diff --git a/Blog.Core.Gateway/appsettings.json b/Blog.Core.Gateway/appsettings.json index 33b99ee8..e63d2990 100644 --- a/Blog.Core.Gateway/appsettings.json +++ b/Blog.Core.Gateway/appsettings.json @@ -1,4 +1,4 @@ -{ +{ "Logging": { "IncludeScopes": false, "Debug": { @@ -14,90 +14,15 @@ } }, "AllowedHosts": "*", - "Startup": { - "Cors": { - "PolicyName": "CorsIpAccess", - "EnableAllIPs": false, - "IPs": "http://127.0.0.1:2364,http://localhost:2364" - } - }, - "Audience": { - "Secret": "sdfsdfsrty45634kkhllghtdgdfss345t678fs", - "SecretFile": "C:\\my-file\\blog.core.audience.secret.txt", - "Issuer": "Blog.Core", - "Audience": "wr" - }, - "WhiteList": [ - { "url": "/" }, - { "url": "/illagal/****" }, - { "url": "/api3/****" }, - { "url": "/baseapi/swagger.json" } - ], - "BlackList": [ - { "url": "/favicon.ico" } - ], - "ApiGateWay": { - "OcelotConfig": "OcelotConfig.json", - "OcelotConfigGroup": "DEFAULT_GROUP", - "AppConfig": "****.****.Gateway.json", - "AppConfigGroup": "DEFAULT_GROUP", - "PermissionServName": "****.****.Api", - "PermissionServGroup": "DEFAULT_GROUP", - "PermissionServUrl": "/api/Permission/GetPermissionlist" - }, - "Influxdb": { - "Endpoint": "http://*******:9328", - "uid": "root", - "pwd": "*****", - "dbname": "mndata" - }, - "nacos": { - "ServerAddresses": [ "http://******:8848/" ], - "ServiceName": "*****.****.Gateway", - "DefaultTimeOut": 15000, - "Namespace": "****", - "ListenInterval": 1000, - "GroupName": "DEFAULT_GROUP", - "ClusterName": "DEFAULT", - "Ip": "", - "PreferredNetworks": "", - "Port": 8090, - "Weight": 100, - "RegisterEnabled": true, - "InstanceEnabled": true, - "Ephemeral": true, - "Secure": false, - "AccessKey": "", - "SecretKey": "", - "UserName": "****", - "Password": "*****", - "NamingUseRpc": true, - "NamingLoadCacheAtStart": "", - "LBStrategy": "WeightRandom", - "Metadata": { - "aa": "bb", - "cc": "dd", - "endpoint33": "******:8090" - } - }, - "nacosConfig": { - "ServiceName": "*****.*****.Gateway", - "Optional": false, - "DataId": "options1", - "Tenant": "******", - "Group": "DEFAULT_GROUP", - "Namespace": "*****", - "ServerAddresses": [ "http://******:8848/" ], - "UserName": "****", - "Password": "*****", - "AccessKey": "", - "SecretKey": "", - "EndPoint": "", - "ConfigUseRpc": true, - "ConfigFilterAssemblies": [ "apigateway" ], - "ConfigFilterExtInfo": "{\"JsonPaths\":[\"ConnectionStrings.Default\"],\"Other\":\"xxxxxx\"}" - } - - + // 自定义配置信息 + "CustomConfigInfo": { + /* + 自定义配置文件目录 + 目录支持程序根目录下和绝对路径 + 如果有多个相同路径的配置,后面将会覆盖前面的内容 + 建议测试类的配置文件夹路径写在后面 + */ + "ConfigFileFolders": [ "CustomConfig" ] + } } diff --git a/Blog.Core.Gateway/ocelot.Production.json b/Blog.Core.Gateway/ocelot.Production.json deleted file mode 100644 index 0db3279e..00000000 --- a/Blog.Core.Gateway/ocelot.Production.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - -} diff --git a/Blog.Core.Gateway/ocelot.Staging.json b/Blog.Core.Gateway/ocelot.Staging.json deleted file mode 100644 index 0db3279e..00000000 --- a/Blog.Core.Gateway/ocelot.Staging.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - -} diff --git a/Blog.Core.Gateway/ocelot.json b/Blog.Core.Gateway/ocelot.json deleted file mode 100644 index 29091fa5..00000000 --- a/Blog.Core.Gateway/ocelot.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - -} \ No newline at end of file diff --git a/Blog.Core.Tests/DependencyInjection/DI_Test.cs b/Blog.Core.Tests/DependencyInjection/DI_Test.cs index ff2c74cd..a38cc2d5 100644 --- a/Blog.Core.Tests/DependencyInjection/DI_Test.cs +++ b/Blog.Core.Tests/DependencyInjection/DI_Test.cs @@ -54,11 +54,11 @@ public static MutiDBOperate GetMainConnectionDb() public IContainer DICollections() { var basePath = AppContext.BaseDirectory; + AppSettings.Init(basePath); IServiceCollection services = new ServiceCollection(); services.AddAutoMapper(typeof(Startup)); - services.AddSingleton(new AppSettings(basePath)); services.AddSingleton(new LogLock(basePath)); services.AddScoped(); services.AddScoped();