Initial import

This commit is contained in:
Stein Helge Riise
2025-11-17 08:32:46 +01:00
commit ede31fbb7e
129 changed files with 9514 additions and 0 deletions
@@ -0,0 +1,34 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "minattest-app-host", "minattest-app-host.csproj", "{DFBC912A-1AC9-4F87-812D-FCC4C619A4BB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{DFBC912A-1AC9-4F87-812D-FCC4C619A4BB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DFBC912A-1AC9-4F87-812D-FCC4C619A4BB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DFBC912A-1AC9-4F87-812D-FCC4C619A4BB}.Debug|x64.ActiveCfg = Debug|Any CPU
{DFBC912A-1AC9-4F87-812D-FCC4C619A4BB}.Debug|x64.Build.0 = Debug|Any CPU
{DFBC912A-1AC9-4F87-812D-FCC4C619A4BB}.Debug|x86.ActiveCfg = Debug|Any CPU
{DFBC912A-1AC9-4F87-812D-FCC4C619A4BB}.Debug|x86.Build.0 = Debug|Any CPU
{DFBC912A-1AC9-4F87-812D-FCC4C619A4BB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DFBC912A-1AC9-4F87-812D-FCC4C619A4BB}.Release|Any CPU.Build.0 = Release|Any CPU
{DFBC912A-1AC9-4F87-812D-FCC4C619A4BB}.Release|x64.ActiveCfg = Release|Any CPU
{DFBC912A-1AC9-4F87-812D-FCC4C619A4BB}.Release|x64.Build.0 = Release|Any CPU
{DFBC912A-1AC9-4F87-812D-FCC4C619A4BB}.Release|x86.ActiveCfg = Release|Any CPU
{DFBC912A-1AC9-4F87-812D-FCC4C619A4BB}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
@@ -0,0 +1,16 @@
namespace minattest_app_host.OpenApi
{
public static class OpenApiExtensions
{
public static void AddSwagger(this IServiceCollection services)
{
services.AddSwaggerGen();
}
public static void UseAppSwagger(this WebApplication app)
{
app.UseSwagger();
app.UseSwaggerUI();
}
}
}
+56
View File
@@ -0,0 +1,56 @@
using Microsoft.Extensions.DependencyInjection.Extensions;
using minattest_app_host.OpenApi;
using Serilog;
using Yarp.ReverseProxy.Forwarder;
Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.WriteTo.Console()
.CreateBootstrapLogger();
try
{
Log.Information("Starting minattest app host");
var builder = WebApplication.CreateBuilder(args);
builder.Host.UseSerilog((context, services, configuration) => configuration
.ReadFrom.Configuration(context.Configuration)
.ReadFrom.Services(services));
builder.Services.AddReverseProxy()
.LoadFromConfig(builder.Configuration.GetSection("ReverseProxy"));
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwagger();
builder.Services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
var app = builder.Build();
app.UseSerilogRequestLogging();
app.Use((context, next) =>
{
context.Request.Scheme = "https";
return next(context);
});
app.UseAppSwagger();
app.UseHttpsRedirection();
app.MapReverseProxy(configure => configure.Use(async (context, next) =>
{
await next();
var errorFeature = context.GetForwarderErrorFeature();
if (errorFeature is not null && errorFeature.Error != ForwarderError.None && errorFeature.Exception != null)
throw errorFeature.Exception;
}));
app.Run();
}
catch (Exception ex)
{
Log.Fatal(ex, "Application terminated unexpectedly");
}
finally
{
Log.CloseAndFlush();
}
@@ -0,0 +1,15 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"MinAttestApp": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:10001;http://localhost:10000",
"dotnetRunMessages": true
}
}
}
+26
View File
@@ -0,0 +1,26 @@
minattest-app-host (BFF)
Overview
- .NET 9 minimal app acting as a reverse proxy for both the React frontend and the API during development.
- Uses YARP to forward:
- `/api/*` to the API (`API_URL`, default `https://localhost:7172`).
- everything else to the frontend dev server (`FRONTEND_URL`, default `http://localhost:5173`).
Configure
- Env vars:
- `FRONTEND_URL` (default: `http://localhost:5173`)
- `API_URL` (default: `https://localhost:7172`)
- `launchSettings.json` sets both for dev profiles.
Run
- Start your API (e.g., at `https://localhost:7172`).
- Start your React dev server (e.g., `npm run dev` on port 5173).
- From repo root: `dotnet run --project frontend/minattest-app-host`
- Open the BFF URL shown in the console (e.g., `https://localhost:10001`).
- Requests to `/api/...` go to your API.
- All other paths (including `/`) go to the React dev server.
Notes
- WebSockets are enabled to support HMR from Vite/CRA dev servers.
- If your API uses the ASP.NET Core dev certificate, ensure it's trusted: `dotnet dev-certs https --trust`.
- Later, add auth and API composition here while keeping the frontend origin hidden from browsers.
@@ -0,0 +1,42 @@
{
"Serilog": {
"Using": [ "Serilog.Sinks.Console" ],
"MinimumLevel": {
"Default": "Verbose",
"Override": {
"Microsoft": "Information",
"System": "Information"
}
},
"WriteTo": [
{
"Name": "Console",
"Args": {
"theme": "Serilog.Sinks.SystemConsole.Themes.AnsiConsoleTheme::Literate, Serilog.Sinks.Console",
"outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}|{RequestId}] {Message:lj} <s:{SourceContext}>{NewLine}{Exception}"
}
}
],
"Enrich": [ "FromLogContext" ]
},
"ReverseProxy": {
"Routes": {
"userApiRoute": {
"ClusterId": "clusterUser",
"Match": {
"Path": "/api/{**catch-all}"
}
}
},
"Clusters": {
"clusterUser": {
"Destinations": {
"destination1": {
"Address": "https://localhost:7172/"
}
}
}
}
},
"AllowedHosts": "*"
}
@@ -0,0 +1,42 @@
{
"Serilog": {
"Using": [ "Serilog.Sinks.Console" ],
"MinimumLevel": {
"Default": "Verbose",
"Override": {
"Microsoft": "Information",
"System": "Information"
}
},
"WriteTo": [
{
"Name": "Console",
"Args": {
"theme": "Serilog.Sinks.SystemConsole.Themes.AnsiConsoleTheme::Literate, Serilog.Sinks.Console",
"outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}|{RequestId}] {Message:lj} <s:{SourceContext}>{NewLine}{Exception}"
}
}
],
"Enrich": [ "FromLogContext" ]
},
"ReverseProxy": {
"Routes": {
"userApiRoute": {
"ClusterId": "clusterUser",
"Match": {
"Path": "/api/{**catch-all}"
}
}
},
"Clusters": {
"clusterUser": {
"Destinations": {
"destination1": {
"Address": "https://localhost:7172/"
}
}
}
}
},
"AllowedHosts": "*"
}
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>minattest_app_host</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Serilog" Version="4.3.0" />
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="9.0.6" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="9.0.6" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="9.0.6" />
<PackageReference Include="Yarp.ReverseProxy" Version="2.1.0" />
</ItemGroup>
</Project>