Ends in:
2 DAYS
5 HRS
11 MIN
43 SEC
Ends in:
2 D
5 H
11 M
43 S
Open Closed

Layered Solution Architecture How to Add an API Gateway #8417


User avatar
0
jonty created
  • ABP Framework version: v8.3.0
  • UI Type: Angular
  • Database System: EF Core (SQL Server.)
  • Tiered (for MVC) or Auth Server Separated (for Angular): yes
  • Exception message and full stack trace:none
  • Steps to reproduce the issue: Hi, Layered Solution Architecture How to add API gateway, I want to proxy the api through the gateway in order to provide services to the outside world, currently I follow Microservice template to create my gateway project, it successfully proxies hostapi service but it is not able to get authorization for authserver what should I do with it, can it be proxied through the gateway?
"ReverseProxy": {
  "Routes": {
    "UnifiedApi": {
      "ClusterId": "HostApiServer",
      "Match": {
        "Path": "/api/{**catch-all}"
      }
    },
    "UnifiedApiSwagger": {
      "ClusterId": "HostApiServer",
      "Match": {
        "Path": "/swagger-json/HostApiServer/swagger/v1/swagger.json"
      },
      "Transforms": [
        { "PathRemovePrefix": "/swagger-json/HostApiServer" }
      ]
    },
    //// 授权服务的路由
    //"AuthServerWellKnown": {
    //  "ClusterId": "AuthServer",
    //  "Match": {
    //    "Path": "/.well-known/openid-configuration"
    //  },
    //  "Order": 1
    //},
    //"AuthServerConnectEndpoints": {
    //  "ClusterId": "AuthServer",
    //  "Match": {
    //    "Path": "/connect/{**catch-all}"
    //  },
    //  "Order": 2
    //}
  },
  "Clusters": {
    "HostApiServer": {
      "Destinations": {
        "HostApiServer": {
          "Address": "http://localhost:44362/"
        }
      }
    },
    //"AuthServer": {
    //  "Destinations": {
    //    "AuthServer": {
    //      "Address": "http://localhost:44333/"
    //    }
    //  }
    //}
  }


5 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    I want to proxy the api through the gateway

    Gateway is like a reverse proxy server.

    Your auth server is localhost:44333, but your swagger website can't reach the auth server.

    Is localhost:44333 available?

  • User Avatar
    0
    jonty created

    hi

    I want to proxy the api through the gateway

    Gateway is like a reverse proxy server.

    Your auth server is localhost:44333, but your swagger website can't reach the auth server.

    Is localhost:44333 available?

    I think I've solved it, I've proxied both authserver and hostapi through gateway, and now I'm left with the last one, and I don't know why I'm getting multiple inputs.

      if (IsSwaggerEnabled(configuration))
      {
          app.UseSwagger();
          app.UseAbpSwaggerUI(options => { ConfigureSwaggerUI(proxyConfig, options, configuration); });
          app.UseRewriter(CreateSwaggerRewriteOptions());
      }
          private static bool IsSwaggerEnabled(IConfiguration configuration)
        {
            return bool.Parse(configuration["Swagger:IsEnabled"] ?? "true");
        }
    
        private void ConfigureSwagger(ServiceConfigurationContext context, IConfiguration configuration)
        {
            if (IsSwaggerEnabled(configuration))
            {
                context.Services.AddAbpSwaggerGen();
            }
        }
    
    
        private static void ConfigureSwaggerUI(
            IProxyConfig proxyConfig,
            SwaggerUIOptions options,
            IConfiguration configuration)
        {
            foreach (var cluster in proxyConfig.Clusters)
            {
                options.SwaggerEndpoint($"/swagger-json/{cluster.ClusterId}/swagger/v1/swagger.json", $"{cluster.ClusterId} API");
            }
    
            options.OAuthClientId(configuration["AuthServer:SwaggerClientId"]);
            options.OAuthScopes(
                "Unified"
            );
        }
    
    

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you check the swagger html page? Maybe it loaded some javascript files multiple times.

  • User Avatar
    0
    jonty created

    Gateway is like a reverse proxy server.

    thank u,it's worked, I'm just using the gateway as a proxy, I don't need to use swagger like microservices, previously I referenced the microservices template.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    : )

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