-
Notifications
You must be signed in to change notification settings - Fork 66
Convert samples to use Aspire #593
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
80483e4
ee239af
2aea7b2
3728b76
96579b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<Sdk Name="Aspire.AppHost.Sdk" /> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net9.0-windows</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<IsAspireHost>true</IsAspireHost> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Aspire.Hosting.AppHost" /> | ||
<PackageReference Include="C3D.Extensions.Aspire.IISExpress" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\AuthRemoteFormsAuthCore\AuthRemoteFormsAuthCore.csproj" /> | ||
<ProjectReference Include="..\AuthRemoteFormsAuthFramework\AuthRemoteFormsAuthFramework.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
var builder = DistributedApplication.CreateBuilder(args); | ||
|
||
var remoteApiKey = builder.AddParameter("apiKey", Guid.NewGuid().ToString(), secret: true); | ||
|
||
var frameworkApp = builder.AddIISExpress("iis") | ||
.AddSiteProject<Projects.AuthRemoteFormsAuthFramework>("framework") | ||
.WithDefaultIISExpressEndpoints() | ||
.WithEnvironment("RemoteApp__ApiKey", remoteApiKey) | ||
.WithHttpHealthCheck(); | ||
|
||
var coreApp = builder.AddProject<Projects.AuthRemoteFormsAuthCore>("core") | ||
.WithEnvironment("RemoteApp__ApiKey", remoteApiKey) | ||
.WithEnvironment("RemoteApp__Url", frameworkApp.GetEndpoint("https")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assuming the resource returned back from the above is not an IResourceWithEnvironment? Otherwise you could just do a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cool. I'll get this merged in and then look at what can make the aspire experience better here |
||
.WithHttpHealthCheck() | ||
.WaitFor(frameworkApp); | ||
|
||
builder.Build().Run(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/launchsettings.json", | ||
"profiles": { | ||
"https": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"applicationUrl": "https://localhost:17095;http://localhost:15283", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development", | ||
"DOTNET_ENVIRONMENT": "Development", | ||
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21002", | ||
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22119" | ||
} | ||
}, | ||
"http": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"applicationUrl": "http://localhost:15283", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development", | ||
"DOTNET_ENVIRONMENT": "Development", | ||
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19075", | ||
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20035" | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning", | ||
"Aspire.Hosting.Dcp": "Warning" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<TargetFramework>net9.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Yarp.ReverseProxy" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\..\src\Microsoft.AspNetCore.SystemWebAdapters.CoreServices\Microsoft.AspNetCore.SystemWebAdapters.CoreServices.csproj" /> | ||
<ProjectReference Include="..\..\ServiceDefaults\Samples.ServiceDefaults.Core\Samples.ServiceDefaults.Core.csproj" /> | ||
</ItemGroup> | ||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
builder.Services.AddReverseProxy().LoadFromConfig(builder.Configuration.GetSection("ReverseProxy")); | ||
builder.AddServiceDefaults(); | ||
|
||
builder.Services.AddReverseProxy(); | ||
|
||
// Add services to the container. | ||
builder.Services.AddControllersWithViews(); | ||
|
@@ -9,8 +11,8 @@ | |
builder.Services.AddSystemWebAdapters() | ||
.AddRemoteAppClient(options => | ||
{ | ||
options.RemoteAppUrl = new(builder.Configuration["ProxyTo"]!); | ||
options.ApiKey = builder.Configuration["RemoteAppApiKey"]!; | ||
options.RemoteAppUrl = new(builder.Configuration["RemoteApp:Url"]!); | ||
options.ApiKey = builder.Configuration["RemoteApp:ApiKey"]!; | ||
}) | ||
.AddAuthenticationClient(true); | ||
|
||
|
@@ -37,6 +39,14 @@ | |
app.MapControllerRoute( | ||
name: "default", | ||
pattern: "{controller=Home}/{action=Index}/{id?}"); | ||
app.MapForwarder("/{**catch-all}", app.Configuration["ProxyTo"]!).WithOrder(int.MaxValue); | ||
|
||
// Configure the the reverse proxy to forward all unhandled requests to the remote app | ||
twsouthwick marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
app.MapForwarder("/{**catch-all}", app.Configuration["RemoteApp:Url"]!) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: If you want to also have HealthChecks enabled, you could also call here the |
||
|
||
// If there is a route locally, we want to ensure that is used by default, but otherwise we'll forward | ||
.WithOrder(int.MaxValue) | ||
|
||
// If we're going to forward the request, there is no need to run any of the middleware after routing | ||
.ShortCircuit(); | ||
|
||
app.Run(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"profiles": { | ||
"FormsAuthCore": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"applicationUrl": "https://localhost:7080;http://localhost:5080", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
"profiles": { | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": false | ||
"launchBrowser": true | ||
} | ||
} | ||
} |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL about these extensions! Preety neat!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes - thanks to some great work by @CZEMacLeod!