skip to Main Content

I have made an API gateway using ocelot which runs on port 8000 and my react app runs on 3000 but when I am trying to redirect it using the API gateway I get error 404

I tried making a react app using create-react-app then just putting it in API gateway but it donot loads.

2

Answers


  1. Chosen as BEST ANSWER

    Thanx for the heads up @Qiang Fu

    1. The solution given above works.
    2. The react app, I build it and then deployed it. It works.

  2. Try modify the PathTemplate of 404 resouce. (Browser F12-network to check)
    You could try the following code.
    ocelot.json

    {
      "Routes": [
        {
          "UpstreamPathTemplate": "/{everything}",
          "UpstreamHttpMethod": [ "Get" ],
          "DownstreamPathTemplate": "/{everything}",
          "DownstreamScheme": "http",
          "DownstreamHostAndPorts": [
            {
              "Host": "localhost",
              "Port": 3000
            }
          ]
        }
      ],
    
      "GlobalConfiguration": {
        "RequestIdKey": "OcRequestId",
        "AdministrationPath": "/administration"
      }
    }
    

    program.cs

    builder.Configuration.AddJsonFile("ocelot.json");
    builder.Services.AddOcelot(builder.Configuration);
    ...
    await app.UseOcelot();
    app.Run();
    

    Test
    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search