I have two web hosts both hosting an API (lets call them Host1 and Host2 for this question).
All API calls (from a ReactApp) go to Host1, and most of them are reverse proxied to Host2.
Some requests need to NOT be reversed proxied, and instead need to be served by Host1 itself.
For example: /api/banana (to Host1) - should be reverse proxied to /api/banana on Host2,
whereas /api/apple (to Host1) - should NOT be reverse proxied, and should be handled by Host1 itself
The reverse proxy (on Host1) knows which requests to forward to Host2.
Problem
When hitting Host1 at /api/ui, I am actually seeing the UI interface for Host1, but I am seeing all the endpoints listed on the left from Host2.
Even though my reverse proxy is configured to NOT reverse proxy the call to /ui or /metadata or /MetadataApp.
I’ve noticed (in fiddler) that the website at Host1 /api/ui is somehow making an API call to /MetadataApp on Host2.
But I have no idea where this is happening in the code, nor how to affect a change on it. Clearly it knows about Host2 somehow?
Which is weird because nowhere in our code are we configuring that URL! its somehow magic.
Question
Where in the code is the UI at /api/ui on Host1 making a call to /MetadataApp and how can I re-configure it to point to Host1, not Host2?
If you’re talking about the Metadata that renders the built-in UI’s, that’s an internal call which embeds the current AppHost’s as embedded JSON in the page, i.e. it’s not a configurable API call.
So I’m not sure where you’re seeing this external /MetadataApp request from?
I’m talking about the call that fetches the JSON data that builds the list of API’s down the lefthand pane.
When running both Host1 and Host2 locally (both on different ports on localhost).
I can see a call to /api/MetadataApp on Host2, that returns all the definitions of the APIs on Host2, whereas I would expect that data to reflect Host1’s API.
In my case, Host1 is on https://localhost:5101/api and Host2 is on https://localhost:5001, and this is what I see in Fiddler:
Damn, Ill need to do something about that, since I do want to use the custom ServiceGateway to forward certain calls to Host1 api onto Host2, but this is not one of them.
No service gateway API goes through ProxyFeature, the service gateway is it’s own configurable client gateway.
If you use a ServiceGatewayFactoryBase you can choose which APIs you want to use a local or external gateway with, e.g:
public class CustomServiceGatewayFactory : ServiceGatewayFactoryBase
{
public override IServiceGateway GetGateway(Type requestType)
{
var isLocal = HostContext.Metadata.RequestTypes.Contains(requestType);
var gateway = isLocal
? (IServiceGateway)base.localGateway
: new JsonServiceClient(alternativeBaseUrl);
return gateway;
}
}