【问题标题】:Route '0' requires Hosts or Path specified. Set the Path to '/{**catchall}' to match all requests路由“0”需要指定主机或路径。将路径设置为“/{**catchall}”以匹配所有请求
【发布时间】:2022-01-25 10:45:02
【问题描述】:

我正在尝试在我的网关应用程序中使用 Yarp 来路由我的应用程序。但是,一旦启动,我就会收到“Route '0' requires Hosts or Path specified. Set the Path to '/{**catchall}' to match all requests.”

这是我的 AppSettings 文件:

 "ReverseProxy": {
    "Routes": [
      {
        "SampleService": {
          "ClusterId": "SampleService-cluster1",
          "Match": {
            "Host": "localhost",
            "Path": "sample/{**catchall}"
          }
        },
        "NotificationService": {
          "ClusterId": "NotificationService-cluster",
          "Match": {
            "Host": "localhost",
            "Path": "api/NotificationService/{**catchall}"
          }
        }
      }
    ],
    "Clusters": {
      "SampleService-cluster1": {
        "Destinations": { "SampleService-cluster1/destination1": { "Address": "http://127.0.0.1:6500" } }
      },
      "NotificationService-cluster": {
        "Destinations": { "NotificationService-cluster/destination1": { "Address": "http://*:6020" } }
      }
    }
  }

配置服务:

public void ConfigureServices(IServiceCollection services)
        {
            services.AddHttpClient();
            services.AddCors(options =>
            {
                options.AddPolicy("any", builder =>
                {
                    builder.AllowAnyOrigin()
                           .AllowAnyMethod()
                           .AllowAnyHeader();
                });
            });

            services.AddControllers();

            services.AddTelemetryConsumer<ForwarderTelemetry>();

            services.AddReverseProxy()
                .LoadFromConfig(Configuration.GetSection("ReverseProxy"));
        }

我明白了: System.InvalidOperationException

那么知道如何解决这个问题吗?

【问题讨论】:

    标签: asp.net asp.net-core reverse-proxy gateway ms-yarp


    【解决方案1】:

    v1.0.0-preview11 中对 Routes 的配置方式进行了重大更改。您需要更新您的设置。

    "ReverseProxy": {
      "Routes": {
        "SampleService": {
          "ClusterId": "SampleService-cluster1",
          "Match": {
            "Host": "localhost",
            "Path": "sample/{**catchall}"
          }
        },
        "NotificationService": {
          "ClusterId": "NotificationService-cluster",
          "Match": {
            "Host": "localhost",
            "Path": "api/NotificationService/{**catchall}"
          }
        }
      },
      "Clusters": {
        "SampleService-cluster1": {
          "Destinations": { "SampleService-cluster1/destination1": { "Address": "http://127.0.0.1:6500" } }
        },
        "NotificationService-cluster": {
          "Destinations": { "NotificationService-cluster/destination1": { "Address": "http://*:6020" } }
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-09-24
      • 1970-01-01
      • 1970-01-01
      • 2013-09-06
      • 1970-01-01
      • 2013-01-02
      • 1970-01-01
      相关资源
      最近更新 更多