ASP.NET Core Api-Gateway middleware
Your architecture design is wrong!
First, let's find out what this the API Gateway.
An API Gateway is programming that sits in front of an application programming interface (API) and acts as a single point of entry for a defined group of microservices.
A major benefit of using API gateways is that they allow developers to encapsulate the internal structure of an application in multiple ways, depending upon use case. This is because, in addition to accommodating direct requests, gateways can be used to invoke multiple back-end services and aggregate the results.
Ok, the name "API Gateway" shows us that it is mostly intended for API services! SPA or MVC applications are not back-end services. You should not put your front-end applications behind the api gateway.
In general, your architecture should look like this:
An API gateway is the single entry point for all clients. SPA is client of your services and should call it through API Gateway. If your application has multiple client apps, that can be a primary pivot when identifying the multiple API Gateways types, so that you can have a different facade for the needs of each client app. This case is a pattern named “Backend for Frontend” (BFF) where each API Gateway can provide a different API tailored for each client app type.
What if you don't want to build a proper architecture?
- You can configure redirect. It is something like to specify a default service of API gateway. Then all clients that go to
http://mygateway:4242/
will redirected tohttp://mygateway:4242/s3/
- Ocelot allows Middleware Injection. So, you can inject your custom middleware where you will check which request and where to redirect it.
- Use CDN to store all css and other content.
- Inline css into html files.