spa proxy 7.0 排除某些路径

问题描述 投票:0回答:1

当我使用 dotnet 7 时

当我的项目包不包含 Microsoft.AspNetCore.proxy 时,当我运行它时,它会提供错误 Microsoft.AspNetCore.proxy not find,当我重新添加时,我需要添加

<SpaProxyServerUrl>https://localhost:44414</SpaProxyServerUrl>

现在的问题是,什么时候做这个, 我想在program.cs中做

app.map.when (context=>!context.request.path.startwithSegments("/swagger"), { builder=> build.useSpa(...)})

将不起作用,这意味着我无法排除某些路径不会路由到前端代理服务器。 我可以知道有什么解决办法吗?

asp.net .net asp.net-core single-page-application
1个回答
0
投票

要排除某些路径路由到前端代理服务器,您可以使用

MapWhen
中间件。 https://learn.microsoft.com/en-us/aspnet/core/fundamentals/middleware/?view=aspnetcore-7.0#branch-the-middleware-pipeline

程序.cs

if (app.Environment.IsDevelopment())
{
    app.UseDeveloperExceptionPage();

    app.MapWhen(context => !context.Request.Path.StartsWithSegments("/swagger"), builder =>
    {
        builder.UseSpa(spa =>
        {
            ....
            ....
        });
    });
}

.......
........

app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "YourApi v1"));

app.UseEndpoints(endpoints =>
{
    endpoints.MapControllers();
});
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.