I’m trying to write a plugin that will act almost like a reverse proxy sitting infront of a number of services (there are various other ServiceStack plugins in the pipeline so it’s not just a reverse proxy but that is one of it’s jobs). The approach I’m looking at is:
- Take incoming request
- Find DTO type from incoming request
- Lookup Consul using DTO type (services are tagged with this in Consul) to find uri of service that will fulfil this request.
- Redirect request to appropriate service.
This is currently in it’s infancy and I’m trying to figure out the best way to achieve this. I am thinking that I will use the pre-defined routes only as it will give a convention that can be used to identify DTO type etc (e.g. Request.RawUrl.SplitOnLast("/")[0]; ) should give DTO type. I’m using the DTO type rather than serializing to strongly typed DTO to avoid needing to add a reference to every possible downstream service.
I’m trying to use a FallbackRoute to catch the requests using the following:
[FallbackRoute("/{Path*}")]
public class Fallback
{
public string Path { get; set; }
}
public class FallBackService : Service
{
public void Any(Fallback fallback){ ... }
}
While testing this I’ve found that any routes that have [xml|json|html|jsv|csv] as first slug and [reply|oneway] as second don’t fallback but instead return a 405. Is there a way round this?
One option that I’ve looked at is having [FallbackRoute(“api/{Path*}”)] as this seems to play well with it but wondering if there’s a way to use the ‘normal’ predefined routes.