'ASP.NET Core 6: How to intercept all incoming requests to call an external service

I am planning to build a micro frontend to intercept and handle all incoming requests just calling an external service that will render the html that the micro frontend must send in the response body.

So, when calling https://www.myurl.com/path-of-url-1 or https://www.myurl.com/subfolder/path-of-url-2 or any other path in the website (IMPORTANT: these url are fake, they don't really exists), it must call MyRenderService.GetResponse(fullpath) or something like that to get the html body and response code (ok, not found, etc) to return to the client.

I don't care of the incoming url asked by the client (maybe they are random, don't know yet), but any incoming request must be handled by MyRenderService.

What about an approach like this?

Program.cs

using ShopWeb.Service;

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.Run(async context =>
{
    await context.Response.WriteAsync(await Renderman.Renderize(context));
});


app.UseHttpsRedirection();
app.Run();


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source