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
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -4,6 +4,9 @@ frontend/.tanstack/
|
|||||||
frontend/.output/
|
frontend/.output/
|
||||||
frontend/.nitro/
|
frontend/.nitro/
|
||||||
releases/
|
releases/
|
||||||
|
LstWrapper/bin
|
||||||
|
LstWrapper/publish
|
||||||
|
LstWrapper/obj
|
||||||
|
|
||||||
# ---> Go
|
# ---> Go
|
||||||
# If you prefer the allow list template instead of the deny list, see community template:
|
# If you prefer the allow list template instead of the deny list, see community template:
|
||||||
@@ -184,3 +187,4 @@ test-results/
|
|||||||
backend/go.sum
|
backend/go.sum
|
||||||
BUILD_NUMBER
|
BUILD_NUMBER
|
||||||
scripts/resetDanger.js
|
scripts/resetDanger.js
|
||||||
|
LstWrapper/Program_vite_as_Static.txt
|
||||||
|
|||||||
9
LstWrapper/LstWrapper.csproj
Normal file
9
LstWrapper/LstWrapper.csproj
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
85
LstWrapper/Program.cs
Normal file
85
LstWrapper/Program.cs
Normal file
@@ -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<HttpContext, Func<Task>, Task>)(async (context, next) =>
|
||||||
|
{
|
||||||
|
var clientFactory = context.RequestServices.GetRequiredService<IHttpClientFactory>();
|
||||||
|
|
||||||
|
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();
|
||||||
23
LstWrapper/Properties/launchSettings.json
Normal file
23
LstWrapper/Properties/launchSettings.json
Normal file
@@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
8
LstWrapper/appsettings.Development.json
Normal file
8
LstWrapper/appsettings.Development.json
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
9
LstWrapper/appsettings.json
Normal file
9
LstWrapper/appsettings.json
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"AllowedHosts": "*"
|
||||||
|
}
|
||||||
15
LstWrapper/web.config
Normal file
15
LstWrapper/web.config
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<configuration>
|
||||||
|
<location path="." inheritInChildApplications="false">
|
||||||
|
<system.webServer>
|
||||||
|
<handlers>
|
||||||
|
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
|
||||||
|
</handlers>
|
||||||
|
<aspNetCore processPath="dotnet"
|
||||||
|
arguments=".\LstWrapper.dll"
|
||||||
|
stdoutLogEnabled="true"
|
||||||
|
stdoutLogFile=".\logs\stdout"
|
||||||
|
hostingModel="inprocess" />
|
||||||
|
</system.webServer>
|
||||||
|
</location>
|
||||||
|
</configuration>
|
||||||
6
LstWrapper/wwwroot/index.html
Normal file
6
LstWrapper/wwwroot/index.html
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<p>The new begining to lst</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user