'Problem with POST verb in ocelot api gateway implementation
Here is my ocelot.json, when I hit GET https://localhost:44368/WeatherForecast it works fine. But when I post a user Login request with POST https://localhost:44368/Login it returns a 404 error. What I actually miss I can't find it out. But when I use a direct URL then it works. swagger_result
Console Log
Error Code: UnableToFindDownstreamRouteError Message: Failed to match Route configuration for upstream path: /Login, verb: POST
ocelot.json file
{
"Routes": [
{
"DownstreamPathTemplate": "/api/WeatherForecast/Get",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": "44385"
}
],
"UpstreamPathTemplate": "/WeatherForecast",
"UpstreamHttpMethod": [
"GET"
]
},
{
"DownstreamPathTemplate": "/api/Auth/Login",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": "44320"
}
],
"UpstreamPathTemplate": "/Login",
"UpstreamHttpMethod": [
"POST"
]
}
]
}
Solution 1:[1]
I found the solution to my problem, that is there is two ocelot.json files based on the environment variable,
- ocelot.json
- ocelot.development.json
I added the downstream mapping on ocelot.json file, but my settings was
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
var env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
webBuilder.UseStartup<Startup>();
webBuilder.ConfigureAppConfiguration(config =>
config.AddJsonFile($"ocelot.{env}.json"));
});
it always finds the ocelot.development.json where I didn't put the downstream mapping for /Login
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Imtiyaz Hossain |
