Implemented SignalR scaling using redis. Improved diagnose report generator. Added SignalR debug card in Diagnose page
This commit is contained in:
@@ -23,15 +23,18 @@ public partial class Startup
|
||||
// we want to use the ApiKey scheme for authenticating the request
|
||||
options.ForwardDefaultSelector = context =>
|
||||
{
|
||||
if (!context.Request.Headers.TryGetValue("Authorization", out var authHeader))
|
||||
return "Session";
|
||||
var headers = context.Request.Headers;
|
||||
|
||||
// For regular api calls
|
||||
if (headers.ContainsKey("Authorization"))
|
||||
return "ApiKey";
|
||||
|
||||
// For websocket requests which cannot use the Authorization header
|
||||
if (headers.Upgrade == "websocket" && headers.Connection == "Upgrade" && context.Request.Query.ContainsKey("access_token"))
|
||||
return "ApiKey";
|
||||
|
||||
var auth = authHeader.FirstOrDefault();
|
||||
|
||||
if (string.IsNullOrEmpty(auth) || !auth.StartsWith("Bearer "))
|
||||
return "Session";
|
||||
|
||||
return "ApiKey";
|
||||
// Regular user traffic/auth
|
||||
return "Session";
|
||||
};
|
||||
})
|
||||
.AddJwtBearer("ApiKey", null, options =>
|
||||
@@ -63,6 +66,16 @@ public partial class Startup
|
||||
|
||||
if (!result)
|
||||
context.Fail("API key has been deleted");
|
||||
},
|
||||
|
||||
OnMessageReceived = context =>
|
||||
{
|
||||
var accessToken = context.Request.Query["access_token"];
|
||||
|
||||
if (!string.IsNullOrEmpty(accessToken))
|
||||
context.Token = accessToken;
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
};
|
||||
})
|
||||
|
||||
25
Moonlight.ApiServer/Startup/Startup.SignalR.cs
Normal file
25
Moonlight.ApiServer/Startup/Startup.SignalR.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Moonlight.ApiServer.Http.Hubs;
|
||||
|
||||
namespace Moonlight.ApiServer.Startup;
|
||||
|
||||
public partial class Startup
|
||||
{
|
||||
public Task RegisterSignalR()
|
||||
{
|
||||
var signalRBuilder = WebApplicationBuilder.Services.AddSignalR();
|
||||
|
||||
if (Configuration.SignalR.UseRedis)
|
||||
signalRBuilder.AddStackExchangeRedis(Configuration.SignalR.RedisConnectionString);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task MapSignalR()
|
||||
{
|
||||
WebApplication.MapHub<DiagnoseHub>("/api/admin/system/diagnose/ws");
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -46,6 +46,7 @@ public partial class Startup
|
||||
await RegisterAuth();
|
||||
await RegisterCors();
|
||||
await RegisterHangfire();
|
||||
await RegisterSignalR();
|
||||
await HookPluginBuild();
|
||||
}
|
||||
|
||||
@@ -62,6 +63,7 @@ public partial class Startup
|
||||
await HookPluginConfigure();
|
||||
|
||||
await MapBase();
|
||||
await MapSignalR();
|
||||
await HookPluginEndpoints();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user