[英]asp.net core swagger RoutePrefix
i had a api site use swagger to expose api. 我有一个api网站,使用swagger公开了api。 dotnet core version is 2.1 and swagger is Swashbuckle.AspNetCore 3.0.0.
dotnet核心版本是2.1,swagger是Swashbuckle.AspNetCore 3.0.0。 my api site is behind a reverse proxy(nginx), the nginx url is https://www.aa.com/chat , map to backen server http://127.0.0.1:5003/ and my swagger config is : ConfigureServices:
我的api网站位于反向代理(nginx)的后面,nginx网址为https://www.aa.com/chat ,映射到后备服务器http://127.0.0.1:5003/,而我的挥霍配置是:ConfigureServices:
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info { Title = "aa.IM.CustomerApi", Version = "v1" });
var basePath = Path.GetDirectoryName(typeof(Program).Assembly.Location);
var controllerXmlPath = Path.Combine(basePath, "aa.IM.CustomerApi.xml");
var entityXmlPath = Path.Combine(basePath, "aa.IM.Entity.xml");
c.IncludeXmlComments(controllerXmlPath);
c.IncludeXmlComments(entityXmlPath);
//c.DescribeAllEnumsAsStrings();
});
Configure: 配置:
app.UseSwagger(c =>
{
});
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("v1/swagger.json", "aa.IM.CustomerApi");
});
then, i can enter into the ui https://www.aa.com/chat/swagger/index.html and then ui can dispaly all perfect, but, when i execute a api (the uri is cus/settings), i found the request url https://www.aa.com/cus/settings is wrong, the correct url is https://www.aa.com/chat/cus/settings . 然后,我可以进入ui https://www.aa.com/chat/swagger/index.html ,然后ui可以显示所有完美的东西,但是,当我执行api(uri是cus / settings)时,我发现请求网址https://www.aa.com/cus/settings错误,正确的网址是https://www.aa.com/chat/cus/settings 。
how can i fix my swagger config to resole the problem? 我该如何解决我的问题配置以解决问题? i had try many way, like http://eatcodelive.com/2017/05/19/change-default-swagger-route-in-an-asp-net-core-web-api/ and How to change base url of Swagger in ASP.NET core but these all can not resolve my problem.
我尝试了很多方法,例如http://eatcodelive.com/2017/05/19/change-default-swagger-route-in-an-asp-net-core-web-api/和如何更改在ASP.NET核心中大摇大摆,但是这些都无法解决我的问题。
You could try rewriting your urls using app.UseRewriter. 您可以尝试使用app.UseRewriter重写您的网址。
app.UseRewriter(new RewriteOptions()
.AddRewrite(@"/cus/settings", "Chat$1", skipRemainingRules: true));
Note that this is untested and just written out of my head. 请注意,这未经测试,只是写在脑海中。
thanks all, i resolved it by below config: 谢谢大家,我通过以下配置解决了它:
app.UseSwagger(c =>
{
c.PreSerializeFilters.Add((doc, requset) =>
{
var root = "https://www.aa.com/chat/";
doc.Host = root;
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.