Dr oscar
Dr oscar

Reputation: 415

Error consume route ApiGateway with ocelot and docker service

I am creating an ApiGateway with ocelot that consume an Api service in net core. The ApiGateway and ApiService are deployed on docker with docker compose of this way: Docker-compose:

tresfilos.webapigateway:
image: ${DOCKER_REGISTRY-}tresfilosapigateway
build: 
  context: .
  dockerfile: tresfilos.ApiGateway/ApiGw-Base/Dockerfile

tresfilos.users.service:
image: ${DOCKER_REGISTRY-}tresfilosusersservice
build: 
  context: .
  dockerfile: tresfilos.Users.Service/tresfilos.Users.Service/Dockerfile

Docker-compose.override:

tresfilos.webapigateway:
environment: 
  - ASPNETCORE_ENVIRONMENT=Development
  - IdentityUrl=http://identity-api
ports:
  - "7000:80"
  - "7001:443"
volumes:
  - ./tresfilos.ApiGateway/Web.Bff:/app/configuration

tresfilos.users.service:
environment: 
  - ASPNETCORE_ENVIRONMENT=Development
  - ASPNETCORE_URLS=https://+:443;http://+:80
ports:
  - "7002:80"
  - "7003:443"
volumes:
  - ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro
  - ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro

In configuration ocelot apigateway i define .json like:

 "ReRoutes": [
 {
   "DownstreamPathTemplate": "/api/{version}/{everything}",
   "DownstreamScheme": "http",
   "DownstreamHostAndPorts": [
     {
       "Host": "tresfilos.users.service",
       "Port": 7002
     }
   ],
   "UpstreamPathTemplate": "/api/{version}/user/{everything}",
   "UpstreamHttpMethod": [ "POST", "PUT", "GET" ]
 },
],
"GlobalConfiguration": {
  "BaseUrl":  "https://localhost:7001"
 }

When i consume the ApiGateway from the url: http://localhost:7000/api/v1/user/Login/authentication

I have the error in terminal docker: enter image description here

Why does the above error occur and how to fix it?

Upvotes: 3

Views: 1476

Answers (2)

Dr oscar
Dr oscar

Reputation: 415

I fix it of this way:

  1. Change ReRoutes to Routes because ocelot version is 16.0.1

  2. Define config like:

    "Routes": [ { "DownstreamPathTemplate": "/api/{version}/{everything}", "DownstreamScheme": "http", "DownstreamHostAndPorts": [ { "Host": "tresfilos.users.service", "Port": 7002 } ], "UpstreamPathTemplate": "/api/{version}/User/{everything}" }, ], "GlobalConfiguration": { "BaseUrl": "https://localhost:7001" }

  3. In postman i send the data in Body like json and not like paramaters.

(JasonS thanks)...

Upvotes: 2

JasonS
JasonS

Reputation: 275

What version of Ocelot are you running?

I found another thread which has a similar looking problem and apparently from version 16.0.0 of Ocelot 'ReRoutes' was changed to 'Routes' in the Ocelot configuration file.

The thread I found was - 404 trying to route the Upstream path to downstream path in Ocelot

Upvotes: 2

Related Questions