refactor(controller): wrapper refactor for dynamic ports
This commit is contained in:
@@ -9,12 +9,15 @@ using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.HttpOverrides;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Register HttpClient so we can proxy HTTP traffic
|
||||
builder.Services.AddHttpClient();
|
||||
|
||||
var app = builder.Build();
|
||||
var port8080 = builder.Configuration.GetValue<int>("ProxyConfig:Port8080", 8080);
|
||||
var port4000 = builder.Configuration.GetValue<int>("ProxyConfig:Port4000", 4000);
|
||||
|
||||
// Enable WebSocket support
|
||||
app.UseWebSockets();
|
||||
@@ -74,14 +77,14 @@ app.Run(async (HttpContext context) =>
|
||||
if (rawPath.StartsWith("/socket.io", StringComparison.OrdinalIgnoreCase) ||
|
||||
rawPath.StartsWith("/lst/socket.io", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
backendHttpBase = "http://localhost:8080";
|
||||
backendWsBase = "ws://localhost:8080";
|
||||
backendHttpBase = $"http://localhost:{port8080}";
|
||||
backendWsBase = $"ws://localhost:{port8080}";
|
||||
}
|
||||
else if (rawPath.StartsWith("/lst/api/controller", StringComparison.OrdinalIgnoreCase) ||
|
||||
rawPath.StartsWith("/api/controller", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
backendHttpBase = "http://localhost:8080";
|
||||
backendWsBase = "ws://localhost:8080";
|
||||
backendHttpBase = $"http://localhost:{port8080}";
|
||||
backendWsBase = $"ws://localhost:{port8080}";
|
||||
|
||||
// Now strip only once
|
||||
// var newPath = rawPath.Substring("/lst".Length);
|
||||
@@ -89,8 +92,8 @@ app.Run(async (HttpContext context) =>
|
||||
}
|
||||
else
|
||||
{
|
||||
backendHttpBase = "http://localhost:4000";
|
||||
backendWsBase = "ws://localhost:4000";
|
||||
backendHttpBase = $"http://localhost:{port4000}";
|
||||
backendWsBase = $"ws://localhost:{port4000}";
|
||||
}
|
||||
|
||||
// Handle WebSocket requests
|
||||
|
||||
Reference in New Issue
Block a user