Ends in:
2 DAYS
1 HR
38 MIN
30 SEC
Ends in:
2 D
1 H
38 M
30 S
Open Closed

Publish API Gateway in IIS ocelot configuration #4815


User avatar
0
andmattia created
  • ABP Framework version: v7.1.0
  • UI type: Angular
  • DB provider: EF Core
    • Tiered (MVC) or Identity Server Separated (Angular): yes

I use a microservice solution and it work fine but still have issue related to API Gateway published on IIS.

app.UseAbpSwaggerUI(options =>
        {
            var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>();
            var routes = configuration.GetSection("Routes").Get<List<OcelotConfiguration>>();
            var routedServices = routes
                .GroupBy(t => t.ServiceKey)
                .Select(r => r.First())
                .Distinct();

            foreach (var config in routedServices.OrderBy(q => q.ServiceKey))
            {
                var url = $"{config.DownstreamScheme}://{config.DownstreamHostAndPorts.FirstOrDefault()?.Host}:{config.DownstreamHostAndPorts.FirstOrDefault()?.Port}";
                // if (!env.IsDevelopment())
                // {
                //     url = $"https://{config.DownstreamHostAndPorts.FirstOrDefault()?.Host}";
                // }

                options.SwaggerEndpoint($"{url}/swagger/v1/swagger.json", $"{config.ServiceKey} API");
                options.OAuthClientId(configuration["AuthServer:SwaggerClientId"]);
            }
        });

I need to change the not development because my IIS has non different name for single service... or all my service need to be available one by one? (ES. auth.mydomain.com, saas.api.mydomain.com,identity.api.mydomain.com, product.api.mydomain.com, ect)?

My api gateway is publish to FQDN to port 443 but all other service is in "localhost" or "machinename" in other port, so when I open the API gateway swagger the Account service works fine

If I use any other service


10 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Can you share the error logs?

  • User Avatar
    0
    andmattia created

    Hi

    I don't have an error on log side but in cosole

    If I try to call via postman the API it works fine

    Can you confirm that the microservice not to be exposed on web but only api gateway?

    So if you look below the name you see the URL and it is the internal URL (es. localhost:45566 or MY-MACHINE-NAME:45566) and of course it doesn't work

  • User Avatar
    0
    andmattia created

    I think this issue is related to the SWAGGER json.

    If I'm inside the network my swagger definition works fine but if I'm outside it doesn't work but API routing works fine inside and outside the network.

    Ocelot not support Swagger documentation

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Can you confirm that the microservice not to be exposed on web but only api gateway?

    If you run your microservices locally, they won't be exposed to the network.

    If I'm inside the network my swagger definition works fine but if I'm outside it doesn't work but API routing works fine inside and outside the network.

    Yes, the swagger will send a request to the backend when you switch the API definition, but the client(browser) doesn't know localhost, so it can't work with your case.

  • User Avatar
    0
    andmattia created

    Ok

    so you confirm that swagger in microservice solution doesn't work if u don't expose the single microservice. I think this is a bis issue...

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    I don't think it's an issue,  If you don't publish to the Internet, how can other clients access its resources?

    And we don't recommend you expose swagger to the internet, other people can easily see all your API definitions.

  • User Avatar
    0
    andmattia created

    Hi,

    I'm not sure that can I understand your reply. I use the eShopLandscape All microservice work on localhost from port 123->128 and API GW replay to api.mydomain.com. Any microservice are directly expose to internet only the GW, but in this case when you try to get the swagger json definition the call we made to localhost and is not possible to complete if you are in the same machine...

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    As I said, the swagger will send a request(AJAX) to the backend from the client(chrome) when you switch the API definition, but the client(browser) doesn't know localhost, so it can't work with your case.

    Maybe I misunderstood your structure.

    At your first screenshot, it looks like a CORS problem.

    You can update the appsettings.json of the service, for example:

  • User Avatar
    0
    andmattia created

    Yes it's exactly our issue.

    So in microservice we can't expose microservices Swagger. I look to a library to do that https://blog.burgyn.online/2020/04/17/swagger-for-ocelot-api-gateway-en.

    I try to invastigate if it's possibile to integrate in ABP.IO

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    ok

Made with ❤️ on ABP v9.1.0-preview. Updated on December 02, 2024, 12:35