Search code examples
asp.net-coreabp-framework

Can you prefix internal ABP routes?


I am using ABP v3.3 on ASP.NET Core 3.1 in a microservice environment.

We are wanting to prefix our microservice routes with the service name. E.g, accounting service would be:

/accounting/api/invoices  
/accounting/api/payments

This is fine with our own controllers as we can define the route with route attributes. E.g [Route("accounting/api/invoices")]

However for internal abp routes like
/api/abp/api-definition
where the controller is defined in the Abp module with these route attributes already applied, how do we go about adding this prefix?

I can’t find anywhere in the documentation anything relating to this, except for the case of conventional controller creation which is not applicable here.

The above is to support the scenario where all microservices are behind an internal load balancer, and all /accounting routes should forward to this single service. This is troublesome currently when using IHttpClientProxy for service-to-service requests, as the /api/abp/api-definition request needs to be forwarded to the specific microservice.

The only alternative approach I have found is to set root paths for all services as http://<loadbalancer>/<servicename>, and then in each service add the line
app.UsePathBase("/accounting")
which strips the above path from the requests to enable route matching.
This however does cause additional issues with the generated Swagger docs from showing this additional route path, which can become confusing.

Any help appreciated


Solution

  • yes but not recommended because you need to replace several code parts. for example