Update log x intercettare richieste IOC
This commit is contained in:
+30
-4
@@ -1,3 +1,4 @@
|
||||
using Microsoft.AspNetCore.Http.Extensions;
|
||||
using MP.IOC.Data;
|
||||
using MP.IOC.Services;
|
||||
using NLog;
|
||||
@@ -86,14 +87,39 @@ var app = builder.Build();
|
||||
// aggiunt base URL x routing corretto
|
||||
string baseUrl = configuration.GetValue<string>("ServerConf:BaseUrl") ?? "";
|
||||
app.UsePathBase(baseUrl);
|
||||
string routePath = configuration.GetValue<string>("ServerConf:RoutePath") ?? "/api/RIOB";
|
||||
string fullPath = $"{baseUrl}{routePath}".Replace("//", "/");
|
||||
logger.Info($"BaseUrl: {baseUrl}");
|
||||
|
||||
// Map route to RouteManager
|
||||
app.Map("/MP/IOC/api/RIOB/{**catchAll}", async (HttpContext ctx) =>
|
||||
app.Use(async (ctx, next) =>
|
||||
{
|
||||
var routeManager = ctx.RequestServices.GetRequiredService<RouteManager>();
|
||||
await routeManager.HandleAsync(ctx);
|
||||
logger.Debug($"Incoming request PathBase='{ctx.Request.PathBase}' Path='{ctx.Request.Path}' RawTarget='{ctx.Request.GetEncodedUrl()}'");
|
||||
await next();
|
||||
});
|
||||
|
||||
|
||||
|
||||
// Map route to RouteManager
|
||||
//app.Map("/MP/IOC/api/RIOB/{**catchAll}", async (HttpContext ctx) =>
|
||||
//{
|
||||
// var routeManager = ctx.RequestServices.GetRequiredService<RouteManager>();
|
||||
// await routeManager.HandleAsync(ctx);
|
||||
//});
|
||||
|
||||
// parametrizzare?!?!?
|
||||
app.MapWhen(ctx =>
|
||||
ctx.Request.Path.StartsWithSegments(fullPath, StringComparison.OrdinalIgnoreCase) ||
|
||||
ctx.Request.Path.StartsWithSegments(routePath, StringComparison.OrdinalIgnoreCase) ||
|
||||
(ctx.Request.PathBase.HasValue && ctx.Request.Path.StartsWithSegments(routePath, StringComparison.OrdinalIgnoreCase)),
|
||||
builder =>
|
||||
{
|
||||
builder.Run(async ctx =>
|
||||
{
|
||||
var routeManager = ctx.RequestServices.GetRequiredService<RouteManager>();
|
||||
await routeManager.HandleAsync(ctx);
|
||||
});
|
||||
});
|
||||
|
||||
logger.Info("App: route Mapped");
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user