转换文件编码

This commit is contained in:
不做码农
2022-06-01 17:25:41 +08:00
parent 3b8ec3cc95
commit b4dceca92f
3 changed files with 70 additions and 70 deletions
+6 -6
View File
@@ -1,21 +1,21 @@
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
#创建 /app文件夹 #创建 /app文件夹
WORKDIR /app WORKDIR /app
#创建挂载目录,用于将程序部署在服务器本地 #创建挂载目录,用于将程序部署在服务器本地
#VOLUME /app #VOLUME /app
#设置docker容器对外暴露端口 #设置docker容器对外暴露端口
EXPOSE 8888 EXPOSE 8888
VOLUME /app/logs VOLUME /app/logs
#COPY bin/Release/net5.0/publish/ app/ #COPY bin/Release/net5.0/publish/ app/
COPY . app/ COPY . app/
#设置容器内的时区,如果不设置,默认时区是标准时间比北京时间晚8个小时 #设置容器内的时区,如果不设置,默认时区是标准时间比北京时间晚8个小时
RUN echo "Asia/shanghai" > /etc/timezone RUN echo "Asia/shanghai" > /etc/timezone
RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# 复制发布文件到工作目录 # 复制发布文件到工作目录
#COPY . app/ #COPY . app/
WORKDIR /app WORKDIR /app
#等价于 dotnet ZR.Admin.WebApi.dll,如果不指定启动端口默认在docker里面启动端口是80端口 #等价于 dotnet ZR.Admin.WebApi.dll,如果不指定启动端口默认在docker里面启动端口是80端口
ENTRYPOINT ["dotnet", "ZR.Admin.WebApi.dll", "--server.urls","http://*:8888"] ENTRYPOINT ["dotnet", "ZR.Admin.WebApi.dll", "--server.urls","http://*:8888"]
+31 -31
View File
@@ -33,39 +33,39 @@ namespace ZR.Admin.WebApi
{ {
string corsUrls = Configuration["corsUrls"]; string corsUrls = Configuration["corsUrls"];
//配置跨域 //配置跨域
services.AddCors(c => services.AddCors(c =>
{ {
c.AddPolicy("Policy", policy => c.AddPolicy("Policy", policy =>
{ {
policy.WithOrigins(corsUrls.Split(',', StringSplitOptions.RemoveEmptyEntries)) policy.WithOrigins(corsUrls.Split(',', StringSplitOptions.RemoveEmptyEntries))
.AllowAnyHeader()//允许任意头 .AllowAnyHeader()//允许任意头
.AllowCredentials()//允许cookie .AllowCredentials()//允许cookie
.AllowAnyMethod();//允许任意方法 .AllowAnyMethod();//允许任意方法
}); });
}); });
//注入SignalR实时通讯,默认用json传输 //注入SignalR实时通讯,默认用json传输
services.AddSignalR(options => services.AddSignalR(options =>
{ {
//客户端发保持连接请求到服务端最长间隔,默认30秒,改成4分钟,网页需跟着设置connection.keepAliveIntervalInMilliseconds = 12e4;即2分钟 //客户端发保持连接请求到服务端最长间隔,默认30秒,改成4分钟,网页需跟着设置connection.keepAliveIntervalInMilliseconds = 12e4;即2分钟
//options.ClientTimeoutInterval = TimeSpan.FromMinutes(4); //options.ClientTimeoutInterval = TimeSpan.FromMinutes(4);
//服务端发保持连接请求到客户端间隔,默认15秒,改成2分钟,网页需跟着设置connection.serverTimeoutInMilliseconds = 24e4;即4分钟 //服务端发保持连接请求到客户端间隔,默认15秒,改成2分钟,网页需跟着设置connection.serverTimeoutInMilliseconds = 24e4;即4分钟
//options.KeepAliveInterval = TimeSpan.FromMinutes(2); //options.KeepAliveInterval = TimeSpan.FromMinutes(2);
}); });
//消除Error unprotecting the session cookie警告 //消除Error unprotecting the session cookie警告
services.AddDataProtection() services.AddDataProtection()
.PersistKeysToFileSystem(new DirectoryInfo(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "DataProtection")); .PersistKeysToFileSystem(new DirectoryInfo(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "DataProtection"));
//普通验证码 //普通验证码
services.AddHeiCaptcha(); services.AddHeiCaptcha();
services.AddIPRate(Configuration); services.AddIPRate(Configuration);
services.AddSession(); services.AddSession();
services.AddMemoryCache(); services.AddMemoryCache();
services.AddHttpContextAccessor(); services.AddHttpContextAccessor();
//绑定整个对象到Model上 //绑定整个对象到Model上
services.Configure<OptionsSetting>(Configuration); services.Configure<OptionsSetting>(Configuration);
//jwt 认证 //jwt 认证
services.AddAuthentication(options => services.AddAuthentication(options =>
{ {
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
@@ -80,7 +80,7 @@ namespace ZR.Admin.WebApi
services.AddMvc(options => services.AddMvc(options =>
{ {
options.Filters.Add(typeof(GlobalActionMonitor));//全局注册 options.Filters.Add(typeof(GlobalActionMonitor));//全局注册
}) })
.AddJsonOptions(options => .AddJsonOptions(options =>
{ {
@@ -99,7 +99,7 @@ namespace ZR.Admin.WebApi
app.UseDeveloperExceptionPage(); app.UseDeveloperExceptionPage();
} }
app.UseSwagger(); app.UseSwagger();
//使可以多次多去body内容 //使可以多次多去body内容
app.Use((context, next) => app.Use((context, next) =>
{ {
context.Request.EnableBuffering(); context.Request.EnableBuffering();
@@ -109,33 +109,33 @@ namespace ZR.Admin.WebApi
} }
return next(); return next();
}); });
//开启访问静态文件/wwwroot目录文件,要放在UseRouting前面 //开启访问静态文件/wwwroot目录文件,要放在UseRouting前面
app.UseStaticFiles(); app.UseStaticFiles();
//开启路由访问 //开启路由访问
app.UseRouting(); app.UseRouting();
app.UseCors("Policy");//要放在app.UseEndpoints前。 app.UseCors("Policy");//要放在app.UseEndpoints前。
//app.UseAuthentication会启用Authentication中间件,该中间件会根据当前Http请求中的Cookie信息来设置HttpContext.User属性(后面会用到), //app.UseAuthentication会启用Authentication中间件,该中间件会根据当前Http请求中的Cookie信息来设置HttpContext.User属性(后面会用到),
//所以只有在app.UseAuthentication方法之后注册的中间件才能够从HttpContext.User中读取到值, //所以只有在app.UseAuthentication方法之后注册的中间件才能够从HttpContext.User中读取到值,
//这也是为什么上面强调app.UseAuthentication方法一定要放在下面的app.UseMvc方法前面,因为只有这样ASP.NET Core的MVC中间件中才能读取到HttpContext.User的值。 //这也是为什么上面强调app.UseAuthentication方法一定要放在下面的app.UseMvc方法前面,因为只有这样ASP.NET Core的MVC中间件中才能读取到HttpContext.User的值。
//1.先开启认证 //1.先开启认证
app.UseAuthentication(); app.UseAuthentication();
//2.再开启授权 //2.再开启授权
app.UseAuthorization(); app.UseAuthorization();
//开启session //开启session
//app.UseSession(); //app.UseSession();
//开启缓存 //开启缓存
app.UseResponseCaching(); app.UseResponseCaching();
//恢复/启动任务 //恢复/启动任务
app.UseAddTaskSchedulers(); app.UseAddTaskSchedulers();
//使用全局异常中间件 //使用全局异常中间件
app.UseMiddleware<GlobalExceptionMiddleware>(); app.UseMiddleware<GlobalExceptionMiddleware>();
//启用客户端IP限制速率 //启用客户端IP限制速率
app.UseIpRateLimiting(); app.UseIpRateLimiting();
app.UseEndpoints(endpoints => app.UseEndpoints(endpoints =>
{ {
//设置socket连接 //设置socket连接
endpoints.MapHub<MessageHub>("/msgHub"); endpoints.MapHub<MessageHub>("/msgHub");
endpoints.MapControllerRoute( endpoints.MapControllerRoute(
@@ -145,7 +145,7 @@ namespace ZR.Admin.WebApi
} }
/// <summary> /// <summary>
/// 注册Services服务 /// 注册Services服务
/// </summary> /// </summary>
/// <param name="services"></param> /// <param name="services"></param>
/// <param name="configuration"></param> /// <param name="configuration"></param>
@@ -153,12 +153,12 @@ namespace ZR.Admin.WebApi
{ {
services.AddAppService(); services.AddAppService();
services.AddSingleton(new AppSettings(configuration)); services.AddSingleton(new AppSettings(configuration));
//开启计划任务 //开启计划任务
services.AddTaskSchedulers(); services.AddTaskSchedulers();
//初始化db //初始化db
DbExtension.AddDb(configuration); DbExtension.AddDb(configuration);
//注册REDIS 服务 //注册REDIS 服务
Task.Run(() => Task.Run(() =>
{ {
//RedisServer.Initalize(); //RedisServer.Initalize();
+33 -33
View File
@@ -7,97 +7,97 @@
} }
}, },
"ConnectionStrings": { "ConnectionStrings": {
"conn_db": "Data Source=LAPTOP-STKF2M8H\\SQLEXPRESS;User ID=sa;Password=zradmin123;Initial Catalog=ZrAdmin;Integrated Security=SSPI", //其他连接字符串请看官方文档 "conn_db": "Data Source=LAPTOP-STKF2M8H\\SQLEXPRESS;User ID=sa;Password=zradmin123;Initial Catalog=ZrAdmin;Integrated Security=SSPI", //其他连接字符串请看官方文档
"conn_db_type": "1" //数据库类型 MySql = 0, SqlServer = 1 "conn_db_type": "1" //数据库类型 MySql = 0, SqlServer = 1
}, },
"urls": "http://localhost:8888", //项目启动url,如果改动端口前端对应devServer也需要进行修改 "urls": "http://localhost:8888", //项目启动url,如果改动端口前端对应devServer也需要进行修改
"corsUrls": "http://localhost:8887", //跨域地址(前端启动项目,前后端分离单独部署需要设置),多个用","隔开 "corsUrls": "http://localhost:8887", //跨域地址(前端启动项目,前后端分离单独部署需要设置),多个用","隔开
"JwtSettings": { "JwtSettings": {
"Issuer": "ZRAdmin.NET", "Issuer": "ZRAdmin.NET",
"Audience": "ZRAdmin.NET", "Audience": "ZRAdmin.NET",
"SecretKey": "SecretKey-ZRADMIN.NET-20210101", "SecretKey": "SecretKey-ZRADMIN.NET-20210101",
"Expire": 1440 //jwt登录过期时间(分) "Expire": 1440 //jwt登录过期时间(分)
}, },
"DemoMode": false, //是否演示模式 "DemoMode": false, //是否演示模式
"Upload": { "Upload": {
"UploadUrl": "http://localhost:8888", "UploadUrl": "http://localhost:8888",
"localSavePath": "" //本地上传文件存储目录/home/website/uploads "localSavePath": "" //本地上传文件存储目录/home/website/uploads
}, },
//阿里云存储配置 //阿里云存储配置
"ALIYUN_OSS": { "ALIYUN_OSS": {
"REGIONID": "cn-hangzhou", "REGIONID": "cn-hangzhou",
"KEY": "XX", "KEY": "XX",
"SECRET": "XX", "SECRET": "XX",
"bucketName": "bucketName", "bucketName": "bucketName",
"domainUrl": "http://xxx.xxx.com" //访问资源域名 "domainUrl": "http://xxx.xxx.com" //访问资源域名
}, },
"gen": { "gen": {
"conn": "Data Source=LAPTOP-STKF2M8H\\SQLEXPRESS;User ID=sa;Password=zradmin123;Initial Catalog=ZrAdmin;Integrated Security=SSPI", "conn": "Data Source=LAPTOP-STKF2M8H\\SQLEXPRESS;User ID=sa;Password=zradmin123;Initial Catalog=ZrAdmin;Integrated Security=SSPI",
"dbType": 1, //MySql = 0, SqlServer = 1 "dbType": 1, //MySql = 0, SqlServer = 1
"autoPre": true, //自动去除表前缀 "autoPre": true, //自动去除表前缀
"author": "admin", "author": "admin",
"tablePrefix": "sys_", //"表前缀(生成类名不会包含表前缀,多个用逗号分隔)", "tablePrefix": "sys_", //"表前缀(生成类名不会包含表前缀,多个用逗号分隔)",
"vuePath": "" //前端代码存储路径eg:D:\Work\ZRAdmin-Vue3 "vuePath": "" //前端代码存储路径eg:D:\Work\ZRAdmin-Vue3
}, },
//邮箱配置信息 //邮箱配置信息
"MailOptions": { "MailOptions": {
//发送人邮箱 //发送人邮箱
"From": "", //eg:xxxx@qq.com "From": "", //eg:xxxx@qq.com
//发送人邮箱密码 //发送人邮箱密码
"Password": "123456", "Password": "123456",
//协议 //协议
"Smtp": "smtp.qq.com", "Smtp": "smtp.qq.com",
"Port": 587 "Port": 587
}, },
//redis服务配置 //redis服务配置
"RedisServer": { "RedisServer": {
"Cache": "127.0.0.1:6379,defaultDatabase=0,poolsize=50,ssl=false,writeBuffer=10240,prefix=cache:", "Cache": "127.0.0.1:6379,defaultDatabase=0,poolsize=50,ssl=false,writeBuffer=10240,prefix=cache:",
"Session": "127.0.0.1:6379,defaultDatabase=0,poolsize=50,ssl=false,writeBuffer=10240,prefix=session:" "Session": "127.0.0.1:6379,defaultDatabase=0,poolsize=50,ssl=false,writeBuffer=10240,prefix=session:"
}, },
//接口请求限制 //接口请求限制
"IpRateLimiting": { "IpRateLimiting": {
//例如设置了5次每分钟访问限流。当False时:项目中每个接口都加入计数,不管你访问哪个接口,只要在一分钟内累计够5次,将禁止访问。 //例如设置了5次每分钟访问限流。当False时:项目中每个接口都加入计数,不管你访问哪个接口,只要在一分钟内累计够5次,将禁止访问。
//True:当一分钟请求了5次GetData接口,则该接口将在时间段内禁止访问,但是还可以访问PostData()5次,总得来说是每个接口都有5次在这一分钟,互不干扰。 //True:当一分钟请求了5次GetData接口,则该接口将在时间段内禁止访问,但是还可以访问PostData()5次,总得来说是每个接口都有5次在这一分钟,互不干扰。
"EnableEndpointRateLimiting": true, "EnableEndpointRateLimiting": true,
//false,拒绝的API调用不会添加到调用次数计数器上;如 客户端每秒发出3个请求并且您设置了每秒一个调用的限制,则每分钟或每天计数器等其他限制将仅记录第一个调用,即成功的API调用。如果您希望被拒绝的API调用计入其他时间的显示(分钟,小时等) //false,拒绝的API调用不会添加到调用次数计数器上;如 客户端每秒发出3个请求并且您设置了每秒一个调用的限制,则每分钟或每天计数器等其他限制将仅记录第一个调用,即成功的API调用。如果您希望被拒绝的API调用计入其他时间的显示(分钟,小时等)
//,则必须设置StackBlockedRequests为true。 //,则必须设置StackBlockedRequests为true。
"StackBlockedRequests": false, "StackBlockedRequests": false,
"RealIpHeader": "X-Real-IP", "RealIpHeader": "X-Real-IP",
//取白名单的客户端ID。如果此标头中存在客户端ID并且与ClientWhitelist中指定的值匹配,则不应用速率限制。 //取白名单的客户端ID。如果此标头中存在客户端ID并且与ClientWhitelist中指定的值匹配,则不应用速率限制。
"ClientIdHeader": "X-ClientId", "ClientIdHeader": "X-ClientId",
"HttpStatusCode": 429, "HttpStatusCode": 429,
//端点白名单 //端点白名单
"EndpointWhitelist": [ "post:/system/dict/data/types", "*:/msghub/negotiate", "*:/LogOut" ], "EndpointWhitelist": [ "post:/system/dict/data/types", "*:/msghub/negotiate", "*:/LogOut" ],
//客户端白名单 //客户端白名单
//"ClientWhitelist": [ "dev-id-1", "dev-id-2" ], //"ClientWhitelist": [ "dev-id-1", "dev-id-2" ],
"QuotaExceededResponse": { "QuotaExceededResponse": {
"Content": "{{\"code\":429,\"msg\":\"访问过于频繁,请稍后重试\"}}", "Content": "{{\"code\":429,\"msg\":\"访问过于频繁,请稍后重试\"}}",
"ContentType": "application/json", "ContentType": "application/json",
"StatusCode": 429 "StatusCode": 429
}, },
//通用规则,api规则,结尾一定要带* //通用规则,api规则,结尾一定要带*
"GeneralRules": [ "GeneralRules": [
{ {
"Endpoint": "*:/captchaImage", "Endpoint": "*:/captchaImage",
//时间段,格式:{数字}{单位};可使用单位:s, m, h, d //时间段,格式:{数字}{单位};可使用单位:s, m, h, d
"Period": "3s", "Period": "3s",
"Limit": 5 "Limit": 5
}, },
{ {
"Endpoint": "post:*", "Endpoint": "post:*",
//时间段,格式:{数字}{单位};可使用单位:s, m, h, d //时间段,格式:{数字}{单位};可使用单位:s, m, h, d
"Period": "3s", "Period": "3s",
"Limit": 1 "Limit": 1
}, },
{ {
"Endpoint": "put:*", "Endpoint": "put:*",
//时间段,格式:{数字}{单位};可使用单位:s, m, h, d //时间段,格式:{数字}{单位};可使用单位:s, m, h, d
"Period": "3s", "Period": "3s",
"Limit": 1 "Limit": 1
} }
//{ //{
// "Endpoint": "*", // "Endpoint": "*",
// //时间段,格式:{数字}{单位};可使用单位:s, m, h, d // //时间段,格式:{数字}{单位};可使用单位:s, m, h, d
// "Period": "1s", // "Period": "1s",
// "Limit": 2 // "Limit": 2
//} //}
@@ -118,7 +118,7 @@
//} //}
], ],
"IpRateLimitPolicies": { "IpRateLimitPolicies": {
//ip规则 //ip规则
"IpRules": [ "IpRules": [
] ]
} }