Open Closed

ABP Ocelot to Yarp special handling route #10553


User avatar
0
DominaTang created

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?

Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

1 Answer(s)
  • User Avatar
    0
    AI-Bot created
    Support Team ABP Agent
    • In ABP’s YARP-based WebGateway, you typically don’t need that app.MapWhen(...) block anymore.

      • In the old Ocelot gateway, MapWhen was used to short-circuit some “local” endpoints (like /api/abp/api-definition and /) so they are handled by the gateway app itself via UseConfiguredEndpoints() 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.
    • What you must ensure after removing MapWhen:

      1. / (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 the MapWhen previously protected.
      2. /api/abp/api-definition behavior:
        • 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 (typical AbpApi route).
        • So you generally want /api/abp/api-definition to be proxied (not handled locally). If your YARP config has the standard ABP route like /api/abp/{**catch-all}, you’re fine.
    • Your new pipeline line app.UseEndpoints(endpoints => endpoints.MapReverseProxy()); is the essential part for YARP. (In minimal hosting, you may also see app.MapReverseProxy(); ABP templates commonly use the UseEndpoints form.)

    If your gateway works and:

    • /swagger (or whatever path you host Swagger UI on) renders locally, and
    • /api/abp/api-definition returns the expected response (likely coming from the proxied service), then you didn’t miss anything from that MapWhen block—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)
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.8.0-preview. Updated on September 28, 2026, 11:44
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.