3

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?

Dr oscar
  • 359
  • 1
  • 4
  • 16

2 Answers2

2

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

JasonS
  • 235
  • 1
  • 8
  • Version 16.0.1, when change to Routes it generates error – Dr oscar Dec 18 '20 at 02:12
  • What error do you get once you change it to Routes? – JasonS Dec 18 '20 at 11:20
  • System.AggregateException: 'One or more errors occurred. (Unable to start Ocelot, errors are: Authentication Options AuthenticationProviderKey:IdentityApiKey,AllowedScopes:[] is unsupported authentication provider)' – Dr oscar Dec 18 '20 at 14:39
2

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)...

Dr oscar
  • 359
  • 1
  • 4
  • 16