Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I cannot see endpoints of microservice in swagger. #316

Closed
47Levan opened this issue Oct 30, 2024 · 1 comment
Closed

I cannot see endpoints of microservice in swagger. #316

47Levan opened this issue Oct 30, 2024 · 1 comment
Assignees

Comments

@47Levan
Copy link

47Levan commented Oct 30, 2024

ocelot.json
Hello . I attached ocelot.json file.

using API;
using Confluent.Kafka;
using Ocelot.DependencyInjection;
using Ocelot.Middleware;

var builder = WebApplication.CreateBuilder(args);

var producerConfig = new ProducerConfig();
builder.Configuration.GetSection("Kafka").Bind(producerConfig);
builder.Configuration.AddJsonFile("ocelot.json", true, true);
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();


builder.Services.AddOcelot(builder.Configuration);
builder.Services.AddSwaggerForOcelot(builder.Configuration);
builder.Services.AddSwaggerGen();

builder.Services.AddSingleton<ProducerConfig>(producerConfig);

var app = builder.Build();
app.UseDeveloperExceptionPage();


app.UseRouting();
app.UseEndpoints(endpoints =>  // Define the endpoint map
{
    endpoints.MapControllers();
});


//app.UseHttpsRedirection();
//app.UseAuthorization();

app.UseSwagger()
   .UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "Swagger.API  v1"))
   .UseSwaggerForOcelotUI()
   .UseOcelot().Wait();

app.Run();

Here is how i configure it
Also here is my docker-compose.yml file code

services:
  gateway-api:
    container_name: gateway-api
    ports:
    - "52791:5000"
    build:
      context: .
      dockerfile: API/Dockerfile
    environment:
      - ASPNETCORE_URLS = "http://*:5000",
      - ASPNETCORE_HTTPS_PORTS = "5050",
      - ASPNETCORE_HTTP_PORTS = "5000"
  points-service:
    container_name: points-service
    depends_on:
    - "gateway-api" 
    ports:
    - "52792:5001"
    environment:
    - ASPNETCORE_URLS="http://*:5001",
    - ASPNETCORE_HTTPS_PORTS="5051",
    - ASPNETCORE_HTTP_PORTS="5001"
    build:
      context: .
      dockerfile: Services/PointsService/PointsService.Api/Dockerfile

And appsettings.json code

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning",
      "Ocelot": "Debug" 
    }
  },
  "Kafka": {
    "BootstrapServers": "broker.local:19092",
    "SecurityProtocol": "Ssl",
    "SslCaLocation": "ssl/ca-cert.pem",
    "SslCertificateLocation": "ssl/client-cert.pem",
    "SslKeyLocation": "ssl/client-key.pem",
    "SslKeyPassword": "123456"
  },
  "Kestrel": {
    "Endpoints": {
      "Http": {
        "Url": "http://*:5000"
      }
    }
  },
  "AllowedHosts": "*"
}

I can call apigateway endpoints without any problems.
But swagger doesn't see service endpoints i checked logs and see this warning.
warn: Ocelot.Responder.Middleware.ResponderMiddleware[0]
2024-10-30 21:04:21 requestId: 0HN7P2MKOVR6R:00000001, previousRequestId: No PreviousRequestId, message: 'Error Code: UnableToFindDownstreamRouteError Message: Failed to match Route configuration for upstream path: /, verb: GET. errors found in ResponderMiddleware. Setting error response for request path:/, request method: GET'

also i run this command from container and it works fine.
curl http://points-service:5001/swagger/v1/swagger.json
Please help me with this i new at the ocelot, and doesn't understand what am i doing wrong.

@47Levan
Copy link
Author

47Levan commented Oct 30, 2024

Fixed issue UseSwagger() .UseSwaggerUI() Can't be used with. UseSwaggerForOcelotUI(). They are cover each other.
After removing UseSwagger and UseSwaggerUI everything works good))

@47Levan 47Levan closed this as completed Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants