Angular等于c#' s&quot usepathbase;

发布于 2025-02-09 11:23:10 字数 377 浏览 1 评论 0原文

我们在AWS ALB背后有一个角度应用。当提出请求到某个路由example.com/balancer-route/....时,负载平衡器将流量引导到Angular应用程序。但这意味着请求在URI中使用其他balancer-route击中Angular应用程序。我们需要忽略这些内容,以便正确提供文件。

C#中的app.usebasepath是否等效?在C#中,这将必不可少/Balancer-Route一部分请求,而是正常的端点。当不存在基本路径时,它也将继续提供请求。

我们知道可以使用NGINX解决这可以解决,但是希望在运行时将路径传递给应用程序的基于应用程序的解决方案。

We have an angular application behind an AWS ALB. The load balancer directs traffic to the angular app when requests are made to a certain route example.com/balancer-route/.... But this then means that requests hit the angular app with the additional balancer-route in the URI. We need these to be ignored so files are served correctly.

Is there an equivalent to app.UseBasePath in C#? In C# this would essential ignore the /balancer-route part of the requests and serve the endpoints as normal. It would also continue to serve requests when the base path is not present.

We're aware this can be solved using NGINX but would prefer an application based solution where the path could be passed to the application at runtime.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

肩上的翅膀 2025-02-16 11:23:10

通过使用重定向角路由功能,您可以获得所需的内容。
以此路线为例:

    const routes: Routes = [
       { path: '', component: HomeComponent },
       { path: 'quotes', component: QuoteListComponent },
       { path: 'quote/:id', component: QuoteComponent }
    ];

您可以向http://some.com/http://some.com/quotes> http:// some.com/quote/1

您要重定向到http://some.com/balancer-routehttp://some.com /balancer-route/quoteshttp://some.com/balancer-route/quote/1分别分别为第一个路由示例。

因此,我们将所有路由将所有路线与儿童路线分组为一个对象,我们将在对所有路线分组的同一对象中添加另一条路线

    const routes: Routes = [
       {
          path: '', children: [
             { path: '', component: HomeComponent },
             { path: 'quotes', component: QuoteListComponent },
             { path: 'quote/:id', component: QuoteComponent }
          ]
       }, {
          path: 'balancer-route', redirectTo: ''
       }
    ];

By using the redirect capabilities of Angular Routing you can get what you are looking for.
Take this routes for example:

    const routes: Routes = [
       { path: '', component: HomeComponent },
       { path: 'quotes', component: QuoteListComponent },
       { path: 'quote/:id', component: QuoteComponent }
    ];

you can surf to http://some.com/, http://some.com/quotes and http://some.com/quote/1,

and, you want to redirect to traffic from http://some.com/balancer-route, http://some.com/balancer-route/quotes and http://some.com/balancer-route/quote/1 to the first routes examples respectively.

Therefore we will group all our Routes into one object with children routes, and we will add another Route with reidrect to the same object that groups all the routes

    const routes: Routes = [
       {
          path: '', children: [
             { path: '', component: HomeComponent },
             { path: 'quotes', component: QuoteListComponent },
             { path: 'quote/:id', component: QuoteComponent }
          ]
       }, {
          path: 'balancer-route', redirectTo: ''
       }
    ];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文