From c68b9f826bb1631fbbf327ca6b46245815ef7115 Mon Sep 17 00:00:00 2001 From: wanggang <76527413@qq.com> Date: Tue, 11 Apr 2023 10:11:10 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=BC=80=E5=8F=91?= =?UTF-8?q?=E5=92=8C=E9=83=A8=E7=BD=B2=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 44 +++++++++++++------------------------------- 1 file changed, 13 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index ef6723d02..f0cd9bf14 100644 --- a/README.md +++ b/README.md @@ -1,42 +1,23 @@ # 开发和部署方式 -## windows x64 下本地开发 +## 开发环境配置 -当前项目基于 .net 6 sdk,安装 visual studio 2022 时通常会自带 +### 软件安装 -### supervisor 方式开发 +1. visual studio 2022(.net 6 sdk) +1. Docker Desktop(wsl2) -1. 根据项目需求,安装 SQL Server 或 MySQL -2. 使用 build/src/win-x64/publish/ 目录下的 dev.start.cmd 和 dev.stop.cmd 管理非数据库依赖 +### 配置文件 -配置文件: +配置文件存储在build\src\docker\publish\conf 目录下,settings 目录存放程序配置文件,其他目录存放依赖配置文件 -1. supervisor: `build\src\win-x64\publish\supervisord\supervisor.dev.conf` -1. nginx: `build\src\win-x64\publish\nginx\conf\nginx.conf` -1. gateway: `build\src\win-x64\publish\gateway\appsettings.json` -1. config: `build\src\win-x64\publish\gateway\wwwroot\settings\appsettings.json` -1. config: `build\src\win-x64\publish\gateway\wwwroot\settings\appsettings.Development.json` +### 依赖管理 -```mermaid -flowchart LR -nginx --localhost:21093--> gateway--localhost:59092--> api:59092 -api:59092 --localhost:6379--> redis:6379 -api:59092 --localhost:13319--> database:13319 -gateway --localhost:8086--> influxdb:8086 -``` - -### Docker Desktop 方式开发 - -1. 无需按照数据库 -2. 使用 build/src/docker/publish/ 目录下的 dev.start.cmd 和 dev.stop.cmd 管理依赖 +使用 build/src/docker/publish/ 目录下的 dev.start.cmd 和 dev.stop.cmd 管理依赖的停止启动,可以在Docker Desktop中查看和管理启动的服务 ## 部署 -### windows x64 supervisor 方式部署 - -1. 执行: `build\src\win-x64\build.cmd` -2. 上传: `build\dist\win-x64\publish` 目录到服务器 -3. 修改配置,执行 publish 目录下的 start.cmd +Docker 和 Windows 部署两种方式只需要按需修改配置文件中的主机名和端口,windows单机部署时使用localhost作为主机名,docker compose单机部署时使用service name 作为主机名 ### docker compose 方式部署 @@ -44,7 +25,8 @@ gateway --localhost:8086--> influxdb:8086 2. 上传: `build\dist\win-x64\publish` 目录到服务器 3. 修改配置,执行 publish 目录下的 start.sh 或 start.cmd -构建时的处理: +### windows x64 方式部署 -1. 复制并重命名 build\src\win-x64\publish\nginx\conf 到 build\dist\docker\publish\conf\nginx,保持nginx的配置文件统一在 build\src\win-x64\publish\nginx\conf 目录维护 -1. 复制 build\src\win-x64\publish\gateway 到 build\dist\docker\publish\gateway,保持网关的配置和应用的配置统一在 build\src\win-x64\publish\gateway 目录维护 +1. 执行: `build\src\win-x64\build.cmd` +2. 上传: `build\dist\win-x64\publish` 目录到服务器 +3. 修改配置,执行 publish 目录下的 start.cmd From 0c8be74969d35ea471d485d7e656ecdc80d455db Mon Sep 17 00:00:00 2001 From: wanggang <76527413@qq.com> Date: Sun, 23 Apr 2023 17:03:41 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=B7=BB=E5=8A=A0api/abp/application-confi?= =?UTF-8?q?guration=E7=9A=84api=E5=8C=85=E8=A3=85=EF=BC=9Aapi/auth/token/a?= =?UTF-8?q?pplication-configuration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TokenService.cs | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/be/Hosts/Auth.Host/src/Win_in.Sfs.Auth.Application/TokenService.cs b/be/Hosts/Auth.Host/src/Win_in.Sfs.Auth.Application/TokenService.cs index c22fde641..56945a228 100644 --- a/be/Hosts/Auth.Host/src/Win_in.Sfs.Auth.Application/TokenService.cs +++ b/be/Hosts/Auth.Host/src/Win_in.Sfs.Auth.Application/TokenService.cs @@ -1,9 +1,10 @@ -using System; using System.ComponentModel.DataAnnotations; using System.Net.Http; +using System.Net.Http.Headers; using System.Threading.Tasks; using IdentityModel.Client; using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; @@ -11,35 +12,31 @@ using Volo.Abp.Application.Services; namespace Win_in.Sfs.Auth.Tokens; -[Route($"api/token")] +[Route($"api")] +[Authorize] public class TokenService : ApplicationService { + private readonly IHttpContextAccessor _httpContextAccessor; private readonly IHttpClientFactory _httpClientFactory; private readonly ILogger _logger; private readonly IConfiguration _configuration; - - public TokenService(IHttpClientFactory httpClientFactory, IConfiguration configuration, ILogger logger) + public TokenService(IHttpContextAccessor httpContextAccessor, IHttpClientFactory httpClientFactory, IConfiguration configuration, ILogger logger) { + this._httpContextAccessor = httpContextAccessor; this._httpClientFactory = httpClientFactory; this._configuration = configuration; this._logger = logger; } - [HttpPost] + [HttpPost("token")] [AllowAnonymous] public async Task CreateAsync(LoginModel model) { var address = _configuration["AuthServer:Authority"]; - var request = new DiscoveryDocumentRequest - { - Address = address, - Policy = new DiscoveryPolicy { RequireHttps = false } - }; - var discovery = await _httpClientFactory.CreateClient().GetDiscoveryDocumentAsync(request).ConfigureAwait(false); var clientId = _configuration["AuthServer:ClientId"]; var clientSecret = _configuration["AuthServer:ClientSecret"]; - this._logger.LogInformation($"address:{address},TokenEndpoint:{discovery.TokenEndpoint},clientId:{clientId},clientSecret:{clientSecret}"); + var result = await _httpClientFactory.CreateClient().RequestPasswordTokenAsync(new PasswordTokenRequest { Address = $"{address.TrimEnd('/')}/connect/token", @@ -49,11 +46,6 @@ public class TokenService : ApplicationService UserName = model.UserName, Password = model.Password }).ConfigureAwait(false); - Console.WriteLine($"Result:${(result.IsError ? result.ErrorDescription : result.AccessToken)}"); - //if (result.RefreshToken == null) - //{ - // throw new UserFriendlyException("用户名或密码错误"); - //} return new JsonResult(new { @@ -72,18 +64,26 @@ public class TokenService : ApplicationService }); } - [HttpGet("[action]")] - [AllowAnonymous] - public string Test() + [HttpGet("token/application-configuration")] + public async Task ApplicationConfiguration() { - return "Test"; + var address = _configuration["AuthServer:Authority"]; + var url = $"{address.TrimEnd('/')}/api/abp/application-configuration"; + var httpClient = _httpClientFactory.CreateClient(); + var token = this._httpContextAccessor.HttpContext.Request.Headers.Authorization.ToString(); + httpClient.DefaultRequestHeaders.Authorization = AuthenticationHeaderValue.Parse(token); + var response = await httpClient.GetAsync(url).ConfigureAwait(false); + var result = new ContentResult(); + result.ContentType = "application/json"; + result.Content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + return result; } - [HttpGet("/token/test")] + [HttpGet("token/test")] [AllowAnonymous] - public string Test1() + public string Test() { - return "Test"; + return "test"; } } From 59b1bd356cd11f1acbe6cbf1dbf37255c7fa65a3 Mon Sep 17 00:00:00 2001 From: wanggang <76527413@qq.com> Date: Sun, 23 Apr 2023 17:31:34 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dnginx=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/src/docker/publish/conf/nginx/nginx.conf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/src/docker/publish/conf/nginx/nginx.conf b/build/src/docker/publish/conf/nginx/nginx.conf index ab34c37d0..09667bbbc 100644 --- a/build/src/docker/publish/conf/nginx/nginx.conf +++ b/build/src/docker/publish/conf/nginx/nginx.conf @@ -59,7 +59,7 @@ http { index index.html; } - location ^/api/ { + location ~* ^/api/ { proxy_pass http://proxy; if ($http_upgrade ~* "close") { break; @@ -81,7 +81,7 @@ http { index index.html; } - location ^/api/ { + location ~* ^/api/ { proxy_pass http://proxy; if ($http_upgrade ~* "close") { break;