Ocelot 网关不想应用微服务路由

问题描述

将单体应用程序分成几个微服务,现在我对如何一起运行它们很感兴趣。 所以,我正在为此构建豹猫网关。还有一些问题。

我尝试将一个简单的微服务与主 API 链接起来。如果我转到网关路由并查询我的微服务 => 我会得到 404。但是,如果我转到该微服务的 uri 我会得到信息。

Ocelot.json / ocelot.Development.json

{
  "Routes": [
    {
      "DownstreamHostAndPorts": [
        {
          "Host": "localhost","Port": 7001
        }
      ],"DownstreamPathTemplate": "/order","DownstreamScheme": "https","UpstreamPathTemplate": "/order","UpstreamHttpMethod": [ "GET" ]
    }
  ],"GlobalConfiguration": {
    "BaseUrl": "https://localhost:5001"
  }
}

程序:

public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .UseSerilog((hostingContext,loggerConfiguration) =>
                {
                    loggerConfiguration.ReadFrom
                        .Configuration(hostingContext.Configuration);
                })
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    var environment = Environment.GetEnvironmentvariable("ASPNETCORE_ENVIRONMENT");

                    webBuilder.ConfigureAppConfiguration(config =>
                    {
                        config
                            .AddJsonFile("ocelot.json")
                            .AddJsonFile($"ocelot.{environment}.json");
                    });

                    webBuilder.UseStartup<Startup>();
                });

启动:

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

            app.UseRouting();
            app.UseAuthorization();
            app.UseAuthentication();
            app.UseSerilogRequestLogging();
            app.UseCors(_AllowSpecificOrigin);

            app.UseSwagger(options =>
            {
                options.SerializeAsV2 = true;
            });

            app.UseSwaggerUI(options =>
            {
                options.SwaggerEndpoint("/swagger/v1/swagger.json","ShoppingCart API");
                options.RoutePrefix = string.Empty;
            });

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
                endpoints.MapControllerRoute(
                    "default","{controller=Products}/{action=GetAll}/{id?}");
            });

            app.USEOcelot();
        }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)