Hi, For the project that I am upgrading from Ocelot (with ABP 8) to Yarp (ABP 10) The gateway module has this code:
app.UseSwagger();
app.UseSwaggerUI(options =>
{
...
});
app.UseAbpSerilogEnrichers();
**app.MapWhen(
ctx => ctx.Request.Path.ToString().StartsWith("/api/abp/api-definition") ||
ctx.Request.Path.ToString().TrimEnd('/').Equals(""),
app2 =>
{
app2.UseRouting();
app2.UseConfiguredEndpoints();
}
);**
//For signalR
app.UseWebSockets();
app.UseOcelot().Wait();
new code: app.UseSwagger(); app.UseAbpSwaggerUI(options => { ConfigureSwaggerUI(proxyConfig, options, configuration); }); app.UseAbpSerilogEnrichers(); app.UseRewriter(CreateSwaggerRewriteOptions()); app.UseWebSockets(); app.UseEndpoints(endpoints => endpoints.MapReverseProxy());
Did I miss anything about the app.MapWhen in new code?
1 Answer(s)
-
0
In ABP’s YARP-based WebGateway, you typically don’t need that
app.MapWhen(...)block anymore.- In the old Ocelot gateway,
MapWhenwas used to short-circuit some “local” endpoints (like/api/abp/api-definitionand/) so they are handled by the gateway app itself viaUseConfiguredEndpoints()instead of being forwarded by Ocelot. - With YARP, ABP’s gateway approach is configuration-driven (ReverseProxy routes/clusters). The “special handling” is now done by:
- your reverse proxy route table (what gets proxied),
- and the gateway’s own middleware/endpoints (Swagger UI, etc.) for what stays local.
- In the old Ocelot gateway,
What you must ensure after removing
MapWhen:/(root) is not being proxied by a YARP route.
If you have a catch-all like/{**catch-all}(or something too broad), it could start proxying the gateway’s home page and Swagger UI, which would break what theMapWhenpreviously protected./api/abp/api-definitionbehavior:- In a microservice solution, this endpoint is usually served by a backend service (commonly Administration service) and the gateway forwards
/api/abp/{**catch-all}to that service (typicalAbpApiroute). - So you generally want
/api/abp/api-definitionto be proxied (not handled locally). If your YARP config has the standard ABP route like/api/abp/{**catch-all}, you’re fine.
- In a microservice solution, this endpoint is usually served by a backend service (commonly Administration service) and the gateway forwards
Your new pipeline line
app.UseEndpoints(endpoints => endpoints.MapReverseProxy());is the essential part for YARP. (In minimal hosting, you may also seeapp.MapReverseProxy(); ABP templates commonly use theUseEndpointsform.)
If your gateway works and:
/swagger(or whatever path you host Swagger UI on) renders locally, and/api/abp/api-definitionreturns the expected response (likely coming from the proxied service), then you didn’t miss anything from thatMapWhenblock—its job has effectively moved to “don’t proxy what should stay local” via the YARP route configuration.
Links (validated):
- https://abp.io/docs/latest/release-info/migration-guides/pro/migrating-to-yarp
- https://abp.io/docs/latest/solution-templates/microservice/adding-new-api-gateways
This response was generated by AI. If it didn’t solve your problem, feel free to post a new answer — our support team will jump in to help you soon.
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)