ThreeMammals / Ocelot

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

Can not reroutes to url with more slash #1177

Closed sunszl closed 4 years ago

sunszl commented 4 years ago

Expected Behavior / New Feature

I want to reroute upstream: /reroute/api/method to downStream: /api/method

Actual Behavior / Motivation for New Feature

It's Ok if there is only the api part. "/reroute/api" will be rerouted to "/api/" But if the method part is added. Ocelot failed to recognize this pattter. put "/reroute/api/method" in ,and it will not trigger the reroute role.

Steps to Reproduce the Problem

  1. this is my reroute config:
    
    {
      "DownstreamPathTemplate": "/{url}",
      "DownstreamScheme": "https",
      "DownstreamHostAndPorts": [
        {
          "Host": "localhost",
          "Port": 44396
        }
      ],
      "UpstreamPathTemplate": "/router/{url}",
      "UpstreamHttpMethod": []
    }
    "BaseUrl": "https://localhost:44315"

2. I type " https://localhost:44315/router/testApi/testMethod", the page still keep there. Failed to reroute to "https://localhost:44396/testApi/testMethod"

## Specifications

  - Version: 14.1.0
  - Platform: .netcore+ vs2019
  - Subsystem: windows10
wast commented 4 years ago

That should work. Move BaseUrl to GlobalConfiguration (read the docs). Also set log level to Trace and check logs from Ocelot.

sunszl commented 4 years ago
{
  "ReRoutes": [
    {

      "DownstreamPathTemplate": "/{everything}",
      "DownstreamScheme": "https",
      "DownstreamHostAndPorts": [
        {
          "Host": "localhost",
          "Port": 44396
        }
      ],
      "ReRouteIsCaseSensitive": false,
      "UpstreamPathTemplate": "/ruter/{everything}",
      "UpstreamHttpMethod": [],
      "RateLimitOptions": {
        "ClientWhitelist": [],
        "EnableRateLimiting": true,
        "Period": "5s",
        "PeriodTimespan": 5,
        "Limit": 2,
        "QuotaExceededMessage": "Customize Tips!"
      }

    }
  ],

  "GlobalConfiguration": {
    "BaseUrl": "https://localhost:44315"
  }
}

this is full version of my ocelot.json. I tried many times, it works for 'https://localhost:44315/api'. But it doesn't works for 'https://localhost:44315/api/method'.

wast commented 4 years ago

I just tested it and it works.

{
      "DownstreamPathTemplate": "/{everything}",
      "DownstreamScheme": "https",
      "DownstreamHostAndPorts": [
        {
          "Host": "jsonplaceholder.typicode.com",
          "Port": 443
        }
      ],
      "UpstreamPathTemplate": "/posts/{everything}",
      "UpstreamHttpMethod": []
    }

Running https://localhost:5001/posts/todos/3 Routes to https://jsonplaceholder.typicode.com/todos/3

sunszl commented 4 years ago

I forgot to set the downstreamRoute. It has nothing to do with ocelot. Ignore this issuse. Anyway thanks for your help.