ThreeMammals / Ocelot

.NET API Gateway
https://www.nuget.org/packages/Ocelot
MIT License
8.38k stars 1.64k forks source link

Ocelot Get 404 Not Found Error #1652

Closed yaolucy007 closed 1 year ago

yaolucy007 commented 1 year ago

I Use Ocelot 16.0.1 As ApiGateway with consul in my project. I have add 3 services to ocelot. if I test with postman,is works good.but if i request in axios.js,some errors make me sad. all of http interface is wokr except one.the request will retuan 404 status code in ocelot. Could you advice me?

my ocelot.json

{
  "GlobalConfiguration": {
    "ReRouteIsCaseSensitive": false,
    "ServiceDiscoveryProvider": { 
      "Host": "192.168.0.110", 
      "Port": 5999, 
      "Type": "Consul"
    }
  },
  "Routes": [
    {
      "DownstreamPathTemplate": "/token",
      "DownstreamScheme": "http",
      "UpServiceDiscovery": true,
      "UpstreamPathTemplate": "/token",
      "UpstreamHttpMethod": [ "Post", "Options" ],
      "ServiceName": "Identity Server In Jwt Api"
    },
    {
      "DownstreamPathTemplate": "/api/version/{action}",   // this is the question where make happen
      "DownstreamScheme": "http",
      "UpServiceDiscovery": true,
      "UpstreamPathTemplate": "/api/version/{action}",
      "UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete", "Options" ],
      "ServiceName": "Business Version Server Api"
    },
    {
      "DownstreamPathTemplate": "/api/user",
      "DownstreamScheme": "http",
      "UpServiceDiscovery": true,
      "UpstreamPathTemplate": "/api/user",
      "UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete", "Batch", "Options" ],
      "ServiceName": "System Server Api"
    },
    {
      "DownstreamPathTemplate": "/api/user/{action}",
      "DownstreamScheme": "http",
      "UpServiceDiscovery": true,
      "UpstreamPathTemplate": "/api/user/{action}",
      "UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete", "Batch", "Options" ],
      "ServiceName": "System Server Api"
    },
    {
      "DownstreamPathTemplate": "/api/role",
      "DownstreamScheme": "http",
      "UpServiceDiscovery": true,
      "UpstreamPathTemplate": "/api/role",
      "UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete", "Batch", "Options" ],
      "ServiceName": "System Server Api"
    },
    {
      "DownstreamPathTemplate": "/api/role/{action}",
      "DownstreamScheme": "http",
      "UpServiceDiscovery": true,
      "UpstreamPathTemplate": "/api/role/{action}",
      "UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete", "Batch", "Options" ],
      "ServiceName": "System Server Api"
    },
    {
      "DownstreamPathTemplate": "/api/department",
      "DownstreamScheme": "http",
      "UpServiceDiscovery": true,
      "UpstreamPathTemplate": "/api/department",
      "UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete", "Batch", "Options" ],
      "ServiceName": "System Server Api"
    },
    {
      "DownstreamPathTemplate": "/api/department/{action}",
      "DownstreamScheme": "http",
      "UpServiceDiscovery": true,
      "UpstreamPathTemplate": "/api/department/{action}",
      "UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete", "Batch", "Options" ],
      "ServiceName": "System Server Api"
    },
    {
      "DownstreamPathTemplate": "/api/permission",
      "DownstreamScheme": "http",
      "UpServiceDiscovery": true,
      "UpstreamPathTemplate": "/api/permission",
      "UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete", "Batch", "Options" ],
      "ServiceName": "System Server Api"
    },
    {
      "DownstreamPathTemplate": "/api/permission/{action}",
      "DownstreamScheme": "http",
      "UpServiceDiscovery": true,
      "UpstreamPathTemplate": "/api/permission/{action}",
      "UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete", "Batch", "Options" ],
      "ServiceName": "System Server Api"
    },
    {
      "DownstreamPathTemplate": "/api/userrole",
      "DownstreamScheme": "http",
      "UpServiceDiscovery": true,
      "UpstreamPathTemplate": "/api/userrole",
      "UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete", "Batch", "Options" ],
      "ServiceName": "System Server Api"
    },
    {
      "DownstreamPathTemplate": "/api/userrole/{action}",
      "DownstreamScheme": "http",
      "UpServiceDiscovery": true,
      "UpstreamPathTemplate": "/api/userrole/{action}",
      "UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete", "Batch", "Options" ],
      "ServiceName": "System Server Api"
    },
    {
      "DownstreamPathTemplate": "/api/rolepermission",
      "DownstreamScheme": "http",
      "UpServiceDiscovery": true,
      "UpstreamPathTemplate": "/api/rolepermission",
      "UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete", "Batch", "Options" ],
      "ServiceName": "System Server Api"
    },
    {
      "DownstreamPathTemplate": "/api/rolepermission/{action}",
      "DownstreamScheme": "http",
      "UpServiceDiscovery": true,
      "UpstreamPathTemplate": "/api/rolepermission/{action}",
      "UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete", "Batch", "Options" ],
      "ServiceName": "System Server Api"
    },
    {
      "DownstreamPathTemplate": "/api/userdepart",
      "DownstreamScheme": "http",
      "UpServiceDiscovery": true,
      "UpstreamPathTemplate": "/api/userdepart",
      "UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete", "Batch", "Options" ],
      "ServiceName": "System Server Api"
    },
    {
      "DownstreamPathTemplate": "/api/userdepart/{action}",
      "DownstreamScheme": "http",
      "UpServiceDiscovery": true,
      "UpstreamPathTemplate": "/api/userdepart/{action}",
      "UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete", "Batch", "Options" ],
      "ServiceName": "System Server Api"
    }
  ]
}

my quest requst is: http://192.168.0.110:50000/api/version/get?key=ROLE_254982093249970176 and this request will be forward to http://192.168.0.110:50004/api/version/get?key=ROLE_254982093249970176

this is the warning info in ocelot process console:

info: Ocelot.RateLimit.Middleware.ClientRateLimitMiddleware[0] requestId: 0HMQGVGK8B1C2:00000001, previousRequestId: no previous request id, message: EndpointRateLimiting is not enabled for /api/version/{action} info: Ocelot.Authentication.Middleware.AuthenticationMiddleware[0] requestId: 0HMQGVGK8B1C2:00000001, previousRequestId: no previous request id, message: No authentication needed for /api/version/get info: Ocelot.Authorisation.Middleware.AuthorisationMiddleware[0] requestId: 0HMQGVGK8B1C2:00000001, previousRequestId: no previous request id, message: /api/version/{action} route does not require user to be authorised warn: Ocelot.Requester.Middleware.HttpRequesterMiddleware[0] requestId: 0HMQGVGK8B1C2:00000001, previousRequestId: no previous request id, message: 404 (Not Found) status code, request uri: http://192.168.0.110:50004/api/version/get?key=ROLE_254982093249970176

raman-m commented 1 year ago

@yaolucy007 Mr. Terry,

First, Could you correct your English grammar mistakes please? It is hard to read your message.

Second, Could you attach Postman screenshots which show that mentioned endpoints are online, please, when you are using localhost deployments?

Third, Could you show Consul configs and show us that the endpoints are registered in Consul registry please?

Finally, Why do you use 16.0.1 version of May 25, 2020 release in May 2023? This release / version is quite outdated! Could you consider upgrading your Visual Studio solution and projects to .NET 7 targeting latest Ocelot 19.0.2 version please? NuGet: Ocelot 19.0.2

yaolucy007 commented 1 year ago

I've solved that problem. Through debugging I found that my service was returning cors errors when receiving requests for options, and after I adjusted the cross-domain policy of the service, everything worked fine.

Also, I was using an older version of the service because the project was running on netcore 3.1