简体   繁体   中英

Request URL error in Swagger for Ocelot like http://http://

I'm using Swagger for Ocelot in .Net microservice gateway. I'm using the following package for ocelot swagger:

Install-Package MMLib.SwaggerForOcelot -Version 1.10.1

I'm getting this following issue.

在此处输入图片说明

As I mentioned in the image, the http is replicating in the gateway request URL

My project config is following,

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
    <UserSecretsId>38efa0b7-845b-41f3-914c-1bfc80defa9b</UserSecretsId>
    <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
    <DockerfileContext>..\..\..\..</DockerfileContext>
    <DockerComposeProjectPath>..\..\..\..\docker-compose.dcproj</DockerComposeProjectPath>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
    <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.9.10" />
    <PackageReference Include="MMLib.SwaggerForOcelot" Version="1.10.0" />
    <PackageReference Include="Ocelot" Version="13.8.0" />
  </ItemGroup>

</Project>

My Ocelot configuration is following,

{
  "ReRoutes": [   
    {
      "DownstreamPathTemplate": "/{everything}",
      "DownstreamScheme": "http",
      "DownstreamHostAndPorts": [
        {
          "Host": "customer.api",
          "Port": 80
        }
      ],
      "UpstreamPathTemplate": "/api/Customer/{everything}",
      "UpstreamHttpMethod": [ "POST", "PUT", "GET", "DELETE", "PATCH" ],
      "SwaggerKey": "skCustomer"
    }
  ],
  "SwaggerEndPoints": [   
    {
      "Key": "skCustomer",
      "Config": [
        {
          "Name": "Customer API",
          "Version": "v1",
          "Url": "http://customer.api:80/CustomerAPI/Customer/swagger.json"
        }
      ]
    }
  ],
  "GlobalConfiguration": {
    "RequestIdKey": "OcRequestId",
    "AdministrationPath": "/administration"
  }
}

My swagger config in startup file is following,

public void ConfigureServices(IServiceCollection services)
        {
            services.AddSwaggerForOcelot(_cfg);
            services.AddOcelot(_cfg);
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public async void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseSwaggerForOcelotUI(_cfg, opt =>
            {
                opt.EndPointBasePath = "/swagger/docs";
            });

            await app.UseOcelot();
        }

It looks like issue The scheme is duplicated .

Unfortunately it is still not fixed.

As a workaround you can downgrade to version 1.8

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM