Skip to content

Commit e509454

Browse files
Merge pull request #42 from henrikhimself/develop
Beta 7
2 parents 096134e + 75a0527 commit e509454

11 files changed

Lines changed: 109 additions & 8 deletions

File tree

Directory.Build.props

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
<Project>
2+
<PropertyGroup>
3+
<PublishRepositoryUrl>true</PublishRepositoryUrl>
4+
<EmbedUntrackedSources>true</EmbedUntrackedSources>
5+
</PropertyGroup>
26
<ItemGroup>
37
<PackageReference Include="Microsoft.CodeAnalysis.CSharp">
48
<PrivateAssets>all</PrivateAssets>
59
</PackageReference>
610
<PackageReference Include="StyleCop.Analyzers">
711
<PrivateAssets>all</PrivateAssets>
812
</PackageReference>
13+
<PackageReference Include="Microsoft.SourceLink.GitHub">
14+
<PrivateAssets>all</PrivateAssets>
15+
</PackageReference>
916
</ItemGroup>
1017
<ItemGroup>
1118
<AdditionalFiles Include="..\..\stylecop.json" />

Directory.Build.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
<Authors>Henrik Jensen</Authors>
9+
<Copyright>Copyright 2026 Henrik Jensen</Copyright>
910
<PackageProjectUrl>https://github.com/henrikhimself/DotNet-ReverseProxy</PackageProjectUrl>
1011
<RepositoryUrl>https://github.com/henrikhimself/DotNet-ReverseProxy.git</RepositoryUrl>
1112
<RepositoryType>git</RepositoryType>

Directory.Packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="9.9.0" />
1212
<PackageVersion Include="Microsoft.Extensions.ServiceDiscovery" Version="10.1.0" />
1313
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
14+
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="10.0.102" />
1415
<PackageVersion Include="NSubstitute" Version="5.3.0" />
1516
<PackageVersion Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.13.0" />
1617
<PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="1.13.0" />

examples/Aspire.AppHost/Properties/launchSettings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"launchBrowser": true,
88
"applicationUrl": "https://localhost:17294",
99
"environmentVariables": {
10+
"ASPNETCORE_PREVENTHOSTINGSTARTUP": "true",
1011
"ASPNETCORE_ENVIRONMENT": "Development",
1112
"DOTNET_ENVIRONMENT": "Development",
1213
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21134",

examples/Aspire.ReverseProxy/Program.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
// Use the configured reverse proxy.
2727
app.UseReverseProxy();
2828

29+
// Use the optional reverse proxy API to manage the reverse proxy configuration at runtime.
30+
// Beware that adding new routes/clusters will clear discovered Aspire resources from the configuration.
31+
// See ReverseProxyApi.http for example usage of the API.
32+
app.UseReverseProxyApi("reverse-proxy-api");
33+
2934
// No further routes are registered. This means that you will get a 404 error status on all requests
3035
// that do not match a proxied Aspire resource.
3136
await app.RunAsync();
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Reverse Proxy API Examples (port can be changed in AppHost)
2+
# The "/reverse-proxy-api" is the base path for the reverse proxy API, which is configured when adding
3+
# the reverse proxy API to the application builder.
4+
@Test_HostAddress = https://localhost:8443
5+
6+
# Get clusters
7+
# View the current clusters configured in the reverse proxy.
8+
GET {{Test_HostAddress}}/reverse-proxy-api/cluster
9+
10+
###
11+
# Add cluster
12+
# Add a cluster that points to the catfact.ninja API. This cluster will be used in the route configuration
13+
# to forward requests to the catfact API.
14+
POST {{Test_HostAddress}}/reverse-proxy-api/cluster
15+
Content-Type: application/json
16+
17+
{
18+
"Clusters": [
19+
{
20+
"ClusterId": "catfact-from-api",
21+
"Destinations": {
22+
"destination1": {
23+
"Address": "https://catfact.ninja/fact"
24+
}
25+
}
26+
}
27+
],
28+
"AllowOverwrite": true
29+
}
30+
31+
###
32+
# Get routes
33+
# View the current routes configured in the reverse proxy. After adding the route, you should see
34+
# the new route in the response.
35+
GET {{Test_HostAddress}}/reverse-proxy-api/route
36+
37+
###
38+
# Add route
39+
# Add a route that matches requests to /catfact and forwards them to the catfact cluster. The route also
40+
# includes a transform to remove the /catfact prefix before forwarding the request to the destination.
41+
POST {{Test_HostAddress}}/reverse-proxy-api/route
42+
Content-Type: application/json
43+
44+
{
45+
"Routes": [
46+
{
47+
"RouteId": "catfact-from-api",
48+
"ClusterId": "catfact-from-api",
49+
"Order": 100,
50+
"Match": {
51+
"Path": "catfact-from-api/{**catch-all}"
52+
},
53+
"Transforms": [
54+
{
55+
"PathRemovePrefix": "/catfact-from-api"
56+
}
57+
]
58+
}
59+
],
60+
"AllowOverwrite": true
61+
}

examples/Aspire.ReverseProxy/appsettings.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,29 @@
88
"AllowedHosts": "*",
99
"SelfSignedCertificate": {
1010
"CaFilePath": "{REVERSEPROXY_HOME}"
11+
},
12+
"ReverseProxy": {
13+
"Routes": {
14+
"catfact-route-from-appsettings": {
15+
"ClusterId": "catfact-cluster-from-appsettings",
16+
"Match": {
17+
"Path": "catfact-from-appsettings/{**catch-all}"
18+
},
19+
"Transforms": [
20+
{
21+
"PathRemovePrefix": "/catfact-from-appsettings"
22+
}
23+
]
24+
}
25+
},
26+
"Clusters": {
27+
"catfact-cluster-from-appsettings": {
28+
"Destinations": {
29+
"destination1": {
30+
"Address": "https://catfact.ninja/fact"
31+
}
32+
}
33+
}
34+
}
1135
}
1236
}

examples/Aspire.Website/Views/Home/Index.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</head>
88
<body>
99
<h1>Website</h1>
10-
<p><b>You should see this page when navigating to "https://example-website.local/".</b></p>
10+
<p><b>You should see this page when navigating to "<a href="https://example-website.local:8443/">https://example-website.local:8443/</a>"</b> (port can be changed in AppHost).</p>
1111
<p>This website does not use SSL. Instead, a secure HTTPS connection is provided by the reverse proxy.</p>
1212
<p>In case "example-website.local" cannot be found then you need to map it in your local hosts file.</p>
1313
</body>

src/ReverseProxy.Aspire/ReverseProxy.Aspire.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<PackageTags>testing;reverse-proxy;aspire</PackageTags>
1414
<PackageReadmeFile>README.md</PackageReadmeFile>
1515
<PackageLicenseFile>LICENSE</PackageLicenseFile>
16-
<Version>1.0.0-beta6</Version>
16+
<Version>1.0.0-beta7</Version>
1717
</PropertyGroup>
1818

1919
<ItemGroup>

src/ReverseProxy/Certificate/CertificateFactory.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,12 @@ public X509Certificate2 CreateCertificate(AsymmetricAlgorithm key, X509Certifica
8383
validTo,
8484
serialNumber);
8585

86-
// EphemeralKeySet is not supported on macOS (requires keychain which writes to disk)
87-
// but is supported on Windows, Linux, iOS/tvOS/MacCatalyst, and Android
88-
var keyStorageFlags = OperatingSystem.IsMacOS()
89-
? X509KeyStorageFlags.Exportable
90-
: X509KeyStorageFlags.Exportable | X509KeyStorageFlags.EphemeralKeySet;
86+
// EphemeralKeySet is only usable on Linux where SslStream is backed by OpenSSL.
87+
// On Windows, Schannel requires the private key to be persisted in a CNG key
88+
// container. On macOS, EphemeralKeySet is not supported (requires keychain).
89+
var keyStorageFlags = OperatingSystem.IsLinux()
90+
? X509KeyStorageFlags.Exportable | X509KeyStorageFlags.EphemeralKeySet
91+
: X509KeyStorageFlags.Exportable;
9192

9293
#pragma warning disable SYSLIB0057 // Type or member is obsolete
9394
var pfx = new X509Certificate2(pfxBytes, (string?)null, keyStorageFlags);

0 commit comments

Comments
 (0)