404 trying to route the Upstream path to downstream path in Ocelot
Asked Answered
M

3

15

I am facing this warning/error while forwarding the incoming http request to the downstream path.

Ocelot.DownstreamRouteFinder.Middleware.DownstreamRouteFinderMiddleware: Warning: requestId: 80000025-0004-fd00-b63f-84710c7967bb, previousRequestId: no previous request id, message: DownstreamRouteFinderMiddleware setting pipeline errors. IDownstreamRouteFinder returned Error Code: UnableToFindDownstreamRouteError Message: Failed to match Route configuration for upstream path: /getDepartment, verb: GET.

Program.cs

public class Program
{
    public static void Main(string[] args)
    {
        CreateWebHostBuilder(args).Build().Run();
    }

    public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
       WebHost.CreateDefaultBuilder(args)
       .ConfigureAppConfiguration((host, config) =>
       {
           config.AddJsonFile("ocelot.json");
       })
    .UseStartup<Startup>();
}

Startup.cs

public IConfiguration Configuration { get; }

public Startup(IConfiguration configuration)
{
    Configuration = configuration;
}

// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
    services.AddOcelot(Configuration);
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public async void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }

    await app.UseOcelot();

    app.Run(async (context) =>
    {
        await context.Response.WriteAsync("Hello World!");
    });
}

ocelot.json

{
  "ReRoutes": [
  {
    "DownstreamPathTemplate": "api/department",
    "DownstreamScheme": "http",
    "DownstreamHostAndPorts": [
    {
      "Host": "localhost",
      "Port": 44388
    }],
    "UpstreamPathTemplate": "/getDepartment",
    "UpstreamHttpMethod": [
      "Get"
    ]
  }],
  "GlobalConfiguration": {
    "BaseUrl": "http://localhost:5000"
  }
}

I am getting Error 404 in this.

Mandorla answered 25/5, 2020 at 7:12 Comment(0)
O
55

If you are using the latest version (16.0.0), change "ReRoutes" to "Routes" in your ocelot.json.

I was having the same problem and then came across this pull request explaining it had been changed to match up with a new Microsoft reverse proxy project (YARP). Their documentation needs updating. https://github.com/ThreeMammals/Ocelot/pull/1239

Oidium answered 25/5, 2020 at 10:25 Comment(0)
C
0

I fixed it. It is only about a Docker case sensitivity problem. I named my Ocelot config file as ocelot.development.Json; however, when I fixed it by using ocelot.Development.json; alternatively, you might you have capitalized ocelot.*

The problem was only the upper case D or O.

Also, the PFB attached screenshot, and follow accordingly.

View Image

Circumscription answered 12/6, 2022 at 8:13 Comment(0)
S
0

I fixed it by adding "DownstreamHttpMethod": "POST" in my ocelot.json file which specified the http method of the downstream API and that fixed the issue.

Shigella answered 13/1, 2023 at 8:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.