From d38c1bdf81d03f19594d3f228fea673b3a8fd474 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=86=9B?= <510423039@qq.com> Date: Sat, 6 Nov 2021 22:00:24 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E9=9B=86=E6=88=90Ocelot=E7=BD=91?= =?UTF-8?q?=E5=85=B3=EF=BC=8CConsul=20=E6=9C=8D=E5=8A=A1=E6=B3=A8=E5=86=8C?= =?UTF-8?q?=E5=92=8C=E5=8F=91=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/WeatherForecastController.cs | 40 ------------------- .../WeatherForecast.cs | 15 ------- .../WebGatewayModule.cs | 1 + .../appsettings.Development.json | 17 ++++++++ .../ProjectNameHttpApiHostModule.cs | 2 +- vben271/.env.development | 4 +- vben271/src/hooks/web/useSignalR.ts | 2 +- 7 files changed, 23 insertions(+), 58 deletions(-) delete mode 100644 aspnet-core/gateways/CompanyName.ProjectName.WebGateway/Controllers/WeatherForecastController.cs delete mode 100644 aspnet-core/gateways/CompanyName.ProjectName.WebGateway/WeatherForecast.cs diff --git a/aspnet-core/gateways/CompanyName.ProjectName.WebGateway/Controllers/WeatherForecastController.cs b/aspnet-core/gateways/CompanyName.ProjectName.WebGateway/Controllers/WeatherForecastController.cs deleted file mode 100644 index 4b0dd1c0..00000000 --- a/aspnet-core/gateways/CompanyName.ProjectName.WebGateway/Controllers/WeatherForecastController.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Logging; - -namespace CompanyName.ProjectName.WebGateway.Controllers -{ - [ApiController] - [Route("[controller]")] - public class WeatherForecastController : ControllerBase - { - private static readonly string[] Summaries = new[] - { - "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", - "Scorching" - }; - - private readonly ILogger _logger; - - public WeatherForecastController(ILogger logger) - { - _logger = logger; - } - - [HttpGet] - public IEnumerable Get() - { - var rng = new Random(); - return Enumerable.Range(1, 5).Select(index => new WeatherForecast - { - Date = DateTime.Now.AddDays(index), - TemperatureC = rng.Next(-20, 55), - Summary = Summaries[rng.Next(Summaries.Length)] - }) - .ToArray(); - } - } -} \ No newline at end of file diff --git a/aspnet-core/gateways/CompanyName.ProjectName.WebGateway/WeatherForecast.cs b/aspnet-core/gateways/CompanyName.ProjectName.WebGateway/WeatherForecast.cs deleted file mode 100644 index d258003e..00000000 --- a/aspnet-core/gateways/CompanyName.ProjectName.WebGateway/WeatherForecast.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; - -namespace CompanyName.ProjectName.WebGateway -{ - public class WeatherForecast - { - public DateTime Date { get; set; } - - public int TemperatureC { get; set; } - - public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); - - public string Summary { get; set; } - } -} \ No newline at end of file diff --git a/aspnet-core/gateways/CompanyName.ProjectName.WebGateway/WebGatewayModule.cs b/aspnet-core/gateways/CompanyName.ProjectName.WebGateway/WebGatewayModule.cs index a6173de7..77623827 100644 --- a/aspnet-core/gateways/CompanyName.ProjectName.WebGateway/WebGatewayModule.cs +++ b/aspnet-core/gateways/CompanyName.ProjectName.WebGateway/WebGatewayModule.cs @@ -41,6 +41,7 @@ namespace CompanyName.ProjectName.WebGateway }); app.UseConfiguredEndpoints(); + app.UseWebSockets(); app.UseOcelot().Wait(); } diff --git a/aspnet-core/gateways/CompanyName.ProjectName.WebGateway/appsettings.Development.json b/aspnet-core/gateways/CompanyName.ProjectName.WebGateway/appsettings.Development.json index 0c877400..f92fb6ab 100644 --- a/aspnet-core/gateways/CompanyName.ProjectName.WebGateway/appsettings.Development.json +++ b/aspnet-core/gateways/CompanyName.ProjectName.WebGateway/appsettings.Development.json @@ -47,6 +47,23 @@ "Put", "Delete" ] + }, + { + "DownstreamPathTemplate": "/{url}", + "DownstreamScheme": "ws", + "DownstreamHostAndPorts": [ + { + "Host": "localhost", + "Port": 44315 + } + ], + "UpstreamPathTemplate": "/ws/{url}", + "UpstreamHttpMethod": [ + "Get", + "Post", + "Put", + "Delete" + ] } ] } diff --git a/aspnet-core/services/host/CompanyName.ProjectName.HttpApi.Host/ProjectNameHttpApiHostModule.cs b/aspnet-core/services/host/CompanyName.ProjectName.HttpApi.Host/ProjectNameHttpApiHostModule.cs index 9371638c..43a15ac7 100644 --- a/aspnet-core/services/host/CompanyName.ProjectName.HttpApi.Host/ProjectNameHttpApiHostModule.cs +++ b/aspnet-core/services/host/CompanyName.ProjectName.HttpApi.Host/ProjectNameHttpApiHostModule.cs @@ -122,7 +122,7 @@ namespace CompanyName.ProjectName Authorization = new[] { new CustomHangfireAuthorizeFilter() }, IgnoreAntiforgeryToken = true }); - + if (configuration.GetValue("Consul:Enabled", false)) { app.UseConsul(); diff --git a/vben271/.env.development b/vben271/.env.development index 0ffa73bb..dd597682 100644 --- a/vben271/.env.development +++ b/vben271/.env.development @@ -28,4 +28,6 @@ VITE_AUTH_URL= http://localhost:44354 # 接口地址 -VITE_API_URL= http://localhost:44314/gateway \ No newline at end of file +VITE_API_URL= http://localhost:44314/gateway + +VITE_WEBSOCKE_URL= http://localhost:44314 \ No newline at end of file diff --git a/vben271/src/hooks/web/useSignalR.ts b/vben271/src/hooks/web/useSignalR.ts index 3f2333de..54542f34 100644 --- a/vben271/src/hooks/web/useSignalR.ts +++ b/vben271/src/hooks/web/useSignalR.ts @@ -22,7 +22,7 @@ export function useSignalR() { const userStore = useUserStoreWithOut(); const token = userStore.getToken; - const url = (import.meta.env.VITE_API_URL as string) + '/signalr/notification'; + const url = (import.meta.env.VITE_WEBSOCKE_URL as string) + '/ws/signalr/notification'; const connection = new signalR.HubConnectionBuilder() .withUrl(url, { accessTokenFactory: () => token,