SignalR 不适用于 Ocelot API 网关

SignalR not working with Ocelot API Gateway

我正在为我的项目使用 ASP.Net 样板架构并使用 Ocelot API 网关。

在不使用网关的情况下,我可以从我的 angular 应用程序成功访问 signalr。

但是当我尝试通过 API 网关访问 signalr 时,所有请求都处于挂起状态并出现此错误

以下是我对信号器的 configuration.json 更改

然后我在网关的 Startup.cs 文件中进行了更改。

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

        if (_ocelotSwaggerConfiguration.IsSwaggerEnabled)
        {
            app.UseSwaggerForOcelotUI(Configuration);
        }

        // Enable ReDoc Documentation
        app.UseReDoc(c =>
        {
            c.DocumentTitle = "AI API";
            c.SpecUrl = "/swagger/docs/v1/pitch-ai";
            c.RoutePrefix = string.Empty;
            c.IndexStream = () => Assembly.GetExecutingAssembly()
                .GetManifestResourceStream("AI.Api.Gateway.api_docs.ui.index.html");
            c.HeadContent = GetRedocHeaderContent();
        });

        app.UseAuthentication();
        app.UseStaticFiles();

        app.UseMetricServer();
        app.UseMiddleware<ResponseMetricMiddleware>();
        app.UseHttpMetrics();
        app.UseWebSockets();
        app.UseHealthChecks("/ready", new HealthCheckOptions
        {
            Predicate = r => r.Tags.Contains("services")
        });

        app.Map("/switch", appBuilder =>
        {
            appBuilder.Run(async context =>
            {
                running = !running;
                await context.Response.WriteAsync($"{Environment.MachineName} running {running}");
            });
        });

        app.UseHealthChecks("/health", new HealthCheckOptions
        {
            Predicate = r => r.Name.Contains("health")
        });

        app.UseMetricsAllEndpoints();
        
        app.UseOcelot().ContinueWith(t => Log.Error(t.Exception.Message, t.Exception), System.Threading.Tasks.TaskContinuationOptions.OnlyOnFaulted);
    }

以下更改对我有用。应用了 configuration.json

中的更改
{
      "DownstreamPathTemplate": "/{everything}",
      "DownstreamScheme": "ws",
      "UpstreamPathTemplate": "/{everything}",
      "UpstreamHttpMethod": [ "GET", "POST", "PUT", "DELETE", "OPTIONS" ],
      "SwaggerKey": "ai",
      "ServiceName": "ai-web-api",
      "RateLimitOptions": {
        "ClientWhitelist": [],
        "EnableRateLimiting": true,
        "Period": "1s",
        "PeriodTimespan": 1,
        "Limit": 10
      }
    }

此外,我发现在网关项目中我不需要Microsoft.AspNetCore.SignalR.Client

我在 Startup.cs

app.UseOcelot() 之前移动了 app.UseWebSockets();