61 lines
1.7 KiB
C#
61 lines
1.7 KiB
C#
using System;
|
|
using Fantasy;
|
|
using Fantasy.Async;
|
|
using Fantasy.Event;
|
|
using Fantasy.Network.HTTP;
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
namespace NBF;
|
|
|
|
public class GameHttpApplicationHandler : AsyncEventSystem<OnConfigureHttpApplication>
|
|
{
|
|
protected override async FTask Handler(OnConfigureHttpApplication self)
|
|
{
|
|
var app = self.Application;
|
|
|
|
app.UseCors("GameClient");
|
|
|
|
app.Use(async (context, next) =>
|
|
{
|
|
var requestId = Guid.NewGuid().ToString("N");
|
|
context.Items["RequestId"] = requestId;
|
|
|
|
var start = DateTime.UtcNow;
|
|
var method = context.Request.Method;
|
|
var path = context.Request.Path;
|
|
var ip = context.Connection.RemoteIpAddress?.ToString();
|
|
|
|
Log.Info($"[HTTP-{requestId}] {method} {path} - IP: {ip}");
|
|
|
|
try
|
|
{
|
|
await next.Invoke();
|
|
|
|
var duration = (DateTime.UtcNow - start).TotalMilliseconds;
|
|
var status = context.Response.StatusCode;
|
|
Log.Info($"[HTTP-{requestId}] {status} - {duration}ms");
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error($"[HTTP-{requestId}] exception: {e.Message}");
|
|
throw;
|
|
}
|
|
});
|
|
|
|
app.UseAuthentication();
|
|
app.UseApiJwtGuard();
|
|
|
|
app.UseAuthorization();
|
|
|
|
app.Use(async (context, next) =>
|
|
{
|
|
context.Response.Headers["X-Game-Server"] = "NBF";
|
|
context.Response.Headers["X-Server-Version"] = "1.0.0";
|
|
await next.Invoke();
|
|
});
|
|
|
|
Log.Info($"[HTTP] game application configured: Scene {self.Scene.SceneConfigId}");
|
|
await FTask.CompletedTask;
|
|
}
|
|
}
|