Skip to content

Commit 3a6fd9f

Browse files
davidfowlCopilotMihaZupanCopilot
authored
Introduce structured configuration model for YARP container app (#3017)
* Introduce structured configuration model for YARP container app Replace ad-hoc config keys (YARP_ENABLE_STATIC_FILES, etc.) with a structured object model (YarpAppConfig) bound from IConfiguration. - Configuration/YarpAppConfig.cs: Root config POCO with all sections - Configuration/YarpAppConfigBinder.cs: Single IConfiguration -> object model conversion, with legacy key mapping - Features/: Modular extension methods per feature (StaticFiles, NavigationFallback, ReverseProxy) - Program.cs: Clean pipeline - ordering is explicit, feature logic is in extension methods - Extensions.cs: Takes YarpAppConfig instead of reading IConfiguration Legacy env vars (YARP_ENABLE_STATIC_FILES, YARP_DISABLE_SPA_FALLBACK, YARP_UNSAFE_OLTP_CERT_ACCEPT_ANY_SERVER_CERTIFICATE) continue to work. New config format: StaticFiles:Enabled=true NavigationFallback:Path=/index.html Refs #3015 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Add StaticSite sample and fix config file webroot resolution Set ContentRootPath and WebRootPath via WebApplicationOptions when a config file is passed, so the default wwwroot directory resolves relative to the config file's location. Add samples/StaticSite/ with index.html, 404.html, hashed CSS, and nested directory pages to exercise static file hosting. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Add StaticSite sample to samples README Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Add startup banner and suppress framework console noise Print a clean startup summary showing config file, webroot, SPA fallback, and listening URLs. Suppress noisy framework logs (DataProtection, Hosting.Lifetime, etc.) on the console provider so docker logs shows only useful information. Banner writes to Console directly so it always shows regardless of log level. Framework logs still flow to other providers (OTEL). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix logging escape hatch: re-add Logging config after default filters Use the AddConfiguration pattern from Aspire to allow users to override our default console log suppression via the standard Logging:Console:LogLevel config section. Our defaults suppress framework noise, but users can re-enable specific categories when debugging. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Trim schema, options, and README to implemented features only Remove unimplemented config sections (Compression, Https, Headers, Redirects, CleanUrls, TrailingSlash, PreCompressed, ErrorPages, NavigationFallback.Exclude) from the schema, options classes, binder, and README. These get added when their features are implemented. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix review findings: clear AsyncLocal after use, handle null directory path - Clear TestConfiguration AsyncLocal value after consuming to prevent test pollution between sequential tests - Handle Path.GetDirectoryName returning null for root paths by falling back to current directory - Improve README with startup banner example, logging docs, accurate project structure Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Simplify README intro Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * README: describe as opinionated YARP distribution Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * README: mention ASP.NET Core and YARP Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * README: reverse proxy first, not static file host Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * README: web server and reverse proxy Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Remove auto-generated yarp.sln Was accidentally created by dotnet build. The repo uses YARP.slnx. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Add StaticSite sample to YARP.slnx Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix markdown lint errors in READMEs Add language specifiers to fenced code blocks and fix table column spacing to pass markdownlint. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Improve test infrastructure and coverage - Add YarpAppConfig object model support to YarpTestApp: tests can construct config as strongly-typed objects that serialize to JSON - Add YarpAppConfigBinderTests: 13 unit tests covering new config format, legacy key mapping, precedence rules, and edge cases - Disable parallel test execution to prevent AsyncLocal race conditions - Update integration tests to demonstrate both object model and dictionary-based config patterns 27 tests total (14 integration + 13 binder unit tests) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Remove unnecessary DisableTestParallelization AsyncLocal is per-execution-context, not per-thread. Each test's WebApplicationFactory runs in its own async context so parallel tests don't interfere with each other's config values. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Simplify AddReverseProxy: use builder.Configuration directly No need to pass IConfiguration separately — it's available on the builder. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix outdated links Co-authored-by: Miha Zupan <mihazupan.zupan1@gmail.com> * Replace section name string literals with nameof in YarpAppConfigBinder Agent-Logs-Url: https://github.com/dotnet/yarp/sessions/539722f2-db88-4a86-9362-d5701423a238 Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com> * Fix PR feedback on container README Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Miha Zupan <mihazupan.zupan1@gmail.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
1 parent 2df9fb4 commit 3a6fd9f

25 files changed

Lines changed: 910 additions & 61 deletions

‎YARP.slnx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
<Project Path="samples/Prometheus/HttpLoadApp/HttpLoadApp.csproj" />
3333
<Project Path="samples/Prometheus/ReverseProxy.Metrics-Prometheus.Sample/ReverseProxy.Metrics.Prometheus.Sample.csproj" />
3434
</Folder>
35+
<Folder Name="/samples/StaticSite/">
36+
<File Path="samples/StaticSite/README.md" />
37+
<File Path="samples/StaticSite/yarp-config.json" />
38+
</Folder>
3539
<Folder Name="/Solution Items/">
3640
<File Path=".editorconfig" />
3741
<File Path="eng/Versions.props" />

‎samples/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ The following samples are provided:
2727
| [Lets Encrypt](ReverseProxy.LetsEncrypt.Sample) | Shows how to use a certificate authority such as Lets Encrypt to set up TLS termination in YARP. |
2828
| [Kubernetes Ingress](KubernetesIngress.Sample) | Shows how to use YARP as a Kubernetes ingress controller |
2929
| [Prometheus](Prometheus) | Shows how to consume the YARP telemetry library and export metrics to external telemetry such as Prometheus |
30+
| [Static Site](StaticSite) | Shows how to use the YARP container application as a static file host with SPA fallback |

‎samples/StaticSite/README.md‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Static Site Sample
2+
3+
A minimal static site served by the YARP container application.
4+
5+
## Run
6+
7+
```bash
8+
# From the repo root
9+
dotnet run --project src/Application/Yarp.Application.csproj -- samples/StaticSite/yarp-config.json
10+
```
11+
12+
Then open http://localhost:5000
13+
14+
## What's in the box
15+
16+
```text
17+
wwwroot/
18+
index.html # Home page
19+
404.html # Custom error page
20+
_astro/main.a1b2c3.css # Hashed asset (simulates Astro build output)
21+
docs/getting-started/index.html # Nested page with directory default document
22+
yarp-config.json # YARP container configuration
23+
```
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>404 - Page Not Found</title>
6+
<link rel="stylesheet" href="/_astro/main.a1b2c3.css">
7+
</head>
8+
<body>
9+
<h1>404 - Page Not Found</h1>
10+
<p>The page you're looking for doesn't exist.</p>
11+
<a href="/">Go home</a>
12+
</body>
13+
</html>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
body {
2+
font-family: system-ui, -apple-system, sans-serif;
3+
max-width: 800px;
4+
margin: 0 auto;
5+
padding: 2rem;
6+
color: #333;
7+
}
8+
nav { margin-bottom: 2rem; }
9+
nav a { margin-right: 1rem; }
10+
h1 { color: #512bd4; }
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Getting Started - YARP</title>
6+
<link rel="stylesheet" href="/_astro/main.a1b2c3.css">
7+
</head>
8+
<body>
9+
<h1>Getting Started</h1>
10+
<p>Learn how to use YARP as a static file host and reverse proxy.</p>
11+
</body>
12+
</html>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>YARP Static Site</title>
7+
<link rel="stylesheet" href="/_astro/main.a1b2c3.css">
8+
</head>
9+
<body>
10+
<nav>
11+
<a href="/">Home</a> |
12+
<a href="/docs/getting-started/">Getting Started</a> |
13+
<a href="/about">About</a>
14+
</nav>
15+
<h1>Welcome to YARP</h1>
16+
<p>This is a static site served by the YARP container.</p>
17+
</body>
18+
</html>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"$schema": "../../src/Application/yarp-config.schema.json",
3+
4+
"StaticFiles": {
5+
"Enabled": true
6+
},
7+
8+
"NavigationFallback": {
9+
"Path": "/index.html"
10+
}
11+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Yarp.Application.Configuration;
5+
6+
public sealed class NavigationFallbackOptions
7+
{
8+
public string? Path { get; set; }
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Yarp.Application.Configuration;
5+
6+
public sealed class StaticFilesOptions
7+
{
8+
public bool Enabled { get; set; }
9+
}

0 commit comments

Comments
 (0)