From d097988dfd38b1ae42a02bc8bad3b262c6423f5b Mon Sep 17 00:00:00 2001 From: Blake Matthes Date: Mon, 14 Jul 2025 21:55:25 -0500 Subject: [PATCH] feat(lstwrapper): added a c# wrapper so we can run on windows server and get ssl this will also allow us to still use docker --- .gitignore | 4 ++ LstWrapper/LstWrapper.csproj | 9 +++ LstWrapper/Program.cs | 85 +++++++++++++++++++++++ LstWrapper/Properties/launchSettings.json | 23 ++++++ LstWrapper/appsettings.Development.json | 8 +++ LstWrapper/appsettings.json | 9 +++ LstWrapper/web.config | 15 ++++ LstWrapper/wwwroot/index.html | 6 ++ 8 files changed, 159 insertions(+) create mode 100644 LstWrapper/LstWrapper.csproj create mode 100644 LstWrapper/Program.cs create mode 100644 LstWrapper/Properties/launchSettings.json create mode 100644 LstWrapper/appsettings.Development.json create mode 100644 LstWrapper/appsettings.json create mode 100644 LstWrapper/web.config create mode 100644 LstWrapper/wwwroot/index.html diff --git a/.gitignore b/.gitignore index e737370..4c7476d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,9 @@ frontend/.tanstack/ frontend/.output/ frontend/.nitro/ releases/ +LstWrapper/bin +LstWrapper/publish +LstWrapper/obj # ---> Go # If you prefer the allow list template instead of the deny list, see community template: @@ -184,3 +187,4 @@ test-results/ backend/go.sum BUILD_NUMBER scripts/resetDanger.js +LstWrapper/Program_vite_as_Static.txt diff --git a/LstWrapper/LstWrapper.csproj b/LstWrapper/LstWrapper.csproj new file mode 100644 index 0000000..6568b3d --- /dev/null +++ b/LstWrapper/LstWrapper.csproj @@ -0,0 +1,9 @@ + + + + net9.0 + enable + enable + + + diff --git a/LstWrapper/Program.cs b/LstWrapper/Program.cs new file mode 100644 index 0000000..ec718ab --- /dev/null +++ b/LstWrapper/Program.cs @@ -0,0 +1,85 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.DependencyInjection; +using System.Net.Http; + +var builder = WebApplication.CreateBuilder(args); +// to build the binary dotnet publish -c Release -o ./publish +// Go backend +builder.Services.AddHttpClient("GoBackend", client => +{ + client.BaseAddress = new Uri("http://localhost:8080"); + client.Timeout = TimeSpan.FromSeconds(30); +}); + +// Node frontend +builder.Services.AddHttpClient("NodeFrontend", client => +{ + client.BaseAddress = new Uri("http://localhost:3000"); + client.Timeout = TimeSpan.FromSeconds(30); +}); + +var app = builder.Build(); + +app.UseStaticFiles(); + +app.Use((Func, Task>)(async (context, next) => +{ + var clientFactory = context.RequestServices.GetRequiredService(); + + var isApiRequest = + context.Request.Path.StartsWithSegments("/api") || + context.Request.Path.StartsWithSegments("/graphql") || + context.Request.Path.StartsWithSegments("/auth") || + !context.Request.Method.Equals("GET", StringComparison.OrdinalIgnoreCase); + + var client = clientFactory.CreateClient(isApiRequest ? "GoBackend" : "NodeFrontend"); + + try + { + var requestUri = context.Request.Path + context.Request.QueryString; + + var request = new HttpRequestMessage( + new HttpMethod(context.Request.Method), + requestUri); + + foreach (var header in context.Request.Headers) + { + if (!request.Headers.TryAddWithoutValidation(header.Key, header.Value.ToArray())) + { + request.Content ??= new StreamContent(context.Request.Body); + request.Content.Headers.TryAddWithoutValidation(header.Key, header.Value.ToArray()); + } + } + + if (context.Request.ContentLength > 0 || context.Request.Headers.ContainsKey("Transfer-Encoding")) + { + request.Content = new StreamContent(context.Request.Body); + } + + var response = await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, context.RequestAborted); + + context.Response.StatusCode = (int)response.StatusCode; + + foreach (var header in response.Headers) + { + context.Response.Headers[header.Key] = header.Value.ToArray(); + } + + foreach (var header in response.Content.Headers) + { + context.Response.Headers[header.Key] = header.Value.ToArray(); + } + + context.Response.Headers.Remove("transfer-encoding"); + + await response.Content.CopyToAsync(context.Response.Body); + } + catch (HttpRequestException ex) + { + context.Response.StatusCode = isApiRequest ? 503 : 502; + await context.Response.WriteAsync($"{(isApiRequest ? "Go API" : "Frontend")} unavailable: {ex.Message}"); + } +})); + +app.Run(); \ No newline at end of file diff --git a/LstWrapper/Properties/launchSettings.json b/LstWrapper/Properties/launchSettings.json new file mode 100644 index 0000000..e5a825f --- /dev/null +++ b/LstWrapper/Properties/launchSettings.json @@ -0,0 +1,23 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "http://localhost:5015", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "https://localhost:7208;http://localhost:5015", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/LstWrapper/appsettings.Development.json b/LstWrapper/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/LstWrapper/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/LstWrapper/appsettings.json b/LstWrapper/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/LstWrapper/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/LstWrapper/web.config b/LstWrapper/web.config new file mode 100644 index 0000000..4957891 --- /dev/null +++ b/LstWrapper/web.config @@ -0,0 +1,15 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/LstWrapper/wwwroot/index.html b/LstWrapper/wwwroot/index.html new file mode 100644 index 0000000..071c3e9 --- /dev/null +++ b/LstWrapper/wwwroot/index.html @@ -0,0 +1,6 @@ + + + +

The new begining to lst

+ +