Repository navigation
[Blazor] Replace DevServer with BlazorGateway for standalone WASM apps #65982
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
Merged
+283
−9
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4e67b88
Add Microsoft.AspNetCore.Components.Gateway for standalone WASM apps
javiercn 2788f74
Replace DevServer with BlazorGateway in E2E test infrastructure
javiercn 645e6ad
Remove --applicationpath parsing from BlazorGateway
javiercn dc41806
Fix SPA fallback: use MapFallbackToFile instead of manifest catch-all
javiercn 2e4a184
Address PR review feedback: add namespace, fix paths, consolidate Spa…
javiercn f5b290d
Track ServiceDiscovery packages via Maestro from dotnet/extensions
javiercn f588866
Add missing ServiceDiscovery PackageVersion properties in Version.Det…
javiercn 8eb3908
Address review feedback: fix runtimeconfig template, tfm, and add tar…
javiercn b4aad61
Revert whitespace-only change to E2ETests.csproj
javiercn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| namespace Microsoft.AspNetCore.Components.Gateway; | ||
|
|
||
| /// <summary> | ||
| /// Intended for framework test use only. | ||
| /// </summary> | ||
| public static class BlazorGateway | ||
| { | ||
| /// <summary> | ||
| /// Builds a <see cref="WebApplication"/> configured as a Blazor Gateway. | ||
| /// Reads ClientApps config section for endpoint manifests and YARP reverse proxy configuration. | ||
| /// </summary> | ||
| public static WebApplication BuildWebHost(string[] args) | ||
| { | ||
| var builder = WebApplication.CreateBuilder(args); | ||
|
|
||
| builder.WebHost.UseStaticWebAssets(); | ||
|
|
||
| var appConfigs = builder.Configuration.GetSection("ClientApps") | ||
| .Get<Dictionary<string, ClientAppConfiguration>>() ?? []; | ||
|
|
||
| var proxySection = builder.Configuration.GetSection("ReverseProxy"); | ||
| var hasProxy = proxySection.Exists(); | ||
|
|
||
| if (hasProxy) | ||
| { | ||
| builder.Services.AddReverseProxy() | ||
| .LoadFromConfig(proxySection) | ||
| .AddServiceDiscoveryDestinationResolver(); | ||
| } | ||
|
|
||
| var app = builder.Build(); | ||
|
|
||
| var pathBase = builder.Configuration.GetValue<string>("pathbase"); | ||
| if (!string.IsNullOrEmpty(pathBase)) | ||
| { | ||
| app.UsePathBase(pathBase); | ||
| } | ||
|
|
||
| if (hasProxy) | ||
| { | ||
| app.MapReverseProxy(); | ||
| } | ||
|
|
||
| foreach (var appConfig in appConfigs.Values) | ||
| { | ||
| if (!string.IsNullOrEmpty(appConfig.ConfigEndpointPath) && !string.IsNullOrEmpty(appConfig.ConfigResponse)) | ||
| { | ||
| app.MapGet(appConfig.ConfigEndpointPath, () => Results.Content(appConfig.ConfigResponse, "application/json")) | ||
| .WithMetadata(new ContentEncodingMetadata("identity", 1.0)); | ||
| } | ||
|
|
||
| if (!string.IsNullOrEmpty(appConfig.EndpointsManifest)) | ||
| { | ||
| app.MapGroup(appConfig.PathPrefix ?? "").MapStaticAssets(appConfig.EndpointsManifest); | ||
| } | ||
| } | ||
|
|
||
| // SPA fallback: serve index.html for any non-file URL path, similar to | ||
| // the old DevServer's MapFallbackToFile("index.html"). This is registered | ||
| // after MapStaticAssets so that specific static file routes take precedence. | ||
| app.MapFallbackToFile("index.html"); | ||
|
Comment on lines
+61
to
+64
Member
Author
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. This is until we get fallbacks on the SDK |
||
|
|
||
| return app; | ||
| } | ||
| } | ||
|
|
||
| sealed class ClientAppConfiguration | ||
| { | ||
| public string? PathPrefix { get; set; } | ||
| public string? EndpointsManifest { get; set; } | ||
| public string? ConfigEndpointPath { get; set; } | ||
| public string? ConfigResponse { get; set; } | ||
| } | ||
69 changes: 69 additions & 0 deletions
69
src/Components/Gateway/src/Microsoft.AspNetCore.Components.Gateway.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework> | ||
| <OutputType>Exe</OutputType> | ||
| <AssemblyName>blazor-gateway</AssemblyName> | ||
| <PackageId>Microsoft.AspNetCore.Components.Gateway</PackageId> | ||
| <IsShippingPackage>true</IsShippingPackage> | ||
| <Description>Gateway server for hosting standalone Blazor WebAssembly applications.</Description> | ||
| <GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
| <!-- Assemblies should not reference this assembly directly --> | ||
| <IsProjectReferenceProvider>false</IsProjectReferenceProvider> | ||
| <AddPublicApiAnalyzers>false</AddPublicApiAnalyzers> | ||
| <Nullable>enable</Nullable> | ||
| <!-- Disable the default runtimeconfig.json in favor of the one we create via template, | ||
| which contains the correct framework version. --> | ||
| <GenerateRuntimeConfigurationFiles>false</GenerateRuntimeConfigurationFiles> | ||
| <!-- Allow direct PackageReference for external packages not in the shared framework --> | ||
| <DisablePackageReferenceRestrictions>true</DisablePackageReferenceRestrictions> | ||
| <!-- Use the shared ASP.NET Core runtime from the SDK targeting pack instead of requiring | ||
| the local shared framework build (Microsoft.AspNetCore.App.Runtime.sfxproj). | ||
| UseAspNetCoreSharedRuntime prevents removal of the KnownFrameworkReference. | ||
| DoNotApplyWorkaroundsToMicrosoftAspNetCoreApp prevents the version override to 10.0.0-dev. --> | ||
| <UseAspNetCoreSharedRuntime>true</UseAspNetCoreSharedRuntime> | ||
| <DoNotApplyWorkaroundsToMicrosoftAspNetCoreApp>true</DoNotApplyWorkaroundsToMicrosoftAspNetCoreApp> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Reference Include="Yarp.ReverseProxy" /> | ||
| <Reference Include="Microsoft.Extensions.ServiceDiscovery" /> | ||
| <Reference Include="Microsoft.Extensions.ServiceDiscovery.Yarp" /> | ||
| </ItemGroup> | ||
|
|
||
| <Target Name="_CreateRuntimeConfig" BeforeTargets="CoreBuild"> | ||
| <PropertyGroup> | ||
| <_RuntimeConfigProperties Condition="'$(IsServicingBuild)' == 'true'"> | ||
| FrameworkVersion=$(AspNetCoreMajorMinorVersion).0; | ||
| </_RuntimeConfigProperties> | ||
| <_RuntimeConfigProperties Condition="'$(IsServicingBuild)' != 'true'"> | ||
| FrameworkVersion=$(SharedFxVersion); | ||
| </_RuntimeConfigProperties> | ||
|
|
||
| <_RuntimeConfigPath>$(OutputPath)blazor-gateway.runtimeconfig.json</_RuntimeConfigPath> | ||
| </PropertyGroup> | ||
|
|
||
| <GenerateFileFromTemplate | ||
| TemplateFile="blazor-gateway.runtimeconfig.json.in" | ||
| Properties="$(_RuntimeConfigProperties)" | ||
| OutputPath="$(_RuntimeConfigPath)" /> | ||
| </Target> | ||
|
|
||
| <!-- Pack settings --> | ||
| <PropertyGroup> | ||
| <GenerateNuspecDependsOn>$(GenerateNuspecDependsOn);publish</GenerateNuspecDependsOn> | ||
| <NoPackageAnalysis>true</NoPackageAnalysis> | ||
| <NuspecFile>Microsoft.AspNetCore.Components.Gateway.nuspec</NuspecFile> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.DotNet.Build.Tasks.Templating" PrivateAssets="All" Version="$(MicrosoftDotNetBuildTasksTemplatingVersion)" IsImplicitlyDefined="true" AllowExplicitReference="true" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <NuspecProperty Include="publishDir=$(PublishDir)" /> | ||
| <NuspecProperty Include="binDir=$(OutputPath)" /> | ||
| <NuspecProperty Include="PackageThirdPartyNoticesFile=$(PackageThirdPartyNoticesFile)" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
13 changes: 13 additions & 0 deletions
13
src/Components/Gateway/src/Microsoft.AspNetCore.Components.Gateway.nuspec
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd"> | ||
| <metadata> | ||
| $CommonMetadataElements$ | ||
| </metadata> | ||
| <files> | ||
| $CommonFileElements$ | ||
| <file src="build\**" target="build" /> | ||
| <file src="$publishDir$**\*" target="tools" /> | ||
| <file src="$PackageThirdPartyNoticesFile$" target=".\THIRD-PARTY-NOTICES.txt" /> | ||
| <file src="$binDir$blazor-gateway.runtimeconfig.json" target="tools\blazor-gateway.runtimeconfig.json" /> | ||
| </files> | ||
| </package> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using Microsoft.AspNetCore.Components.Gateway; | ||
|
|
||
| BlazorGateway.BuildWebHost(args).Run(); |
10 changes: 10 additions & 0 deletions
10
src/Components/Gateway/src/blazor-gateway.runtimeconfig.json.in
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
|
javiercn marked this conversation as resolved.
Resolved
|
||
| "runtimeOptions": { | ||
| "tfm": "net11.0", | ||
| "framework": { | ||
| "name": "Microsoft.AspNetCore.App", | ||
| "version": "${FrameworkVersion}" | ||
| }, | ||
| "rollForwardOnNoCandidateFx": 2 | ||
| } | ||
| } | ||
17 changes: 17 additions & 0 deletions
17
src/Components/Gateway/src/build/Microsoft.AspNetCore.Components.Gateway.targets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <Project> | ||
| <PropertyGroup> | ||
| <_BlazorGatewayDll Condition="'$(_BlazorGatewayDll)' == ''">$(MSBuildThisFileDirectory)../tools/blazor-gateway.dll</_BlazorGatewayDll> | ||
| <!-- Prevents the runtime SDK (Microsoft.NET.Sdk.WebAssembly.Browser.targets) from overriding | ||
| RunCommand/RunArguments with WasmAppHost when _UseBlazorDevServer is false. --> | ||
| <_WebAssemblyUserRunParameters>true</_WebAssemblyUserRunParameters> | ||
|
javiercn marked this conversation as resolved.
Resolved
|
||
| </PropertyGroup> | ||
|
|
||
| <Target Name="_BlazorGatewayComputeRunArguments" AfterTargets="ComputeRunArguments" DependsOnTargets="ResolveStaticWebAssetsConfiguration"> | ||
|
javiercn marked this conversation as resolved.
Resolved
|
||
| <PropertyGroup> | ||
| <RunCommand>dotnet</RunCommand> | ||
| <_GatewayStaticWebAssetsManifest>$([System.IO.Path]::Combine('$(MSBuildProjectDirectory)', '$(StaticWebAssetDevelopmentManifestPath)'))</_GatewayStaticWebAssetsManifest> | ||
| <_GatewayEndpointsManifest>$([System.IO.Path]::Combine('$(MSBuildProjectDirectory)', '$(StaticWebAssetEndpointsBuildManifestPath)'))</_GatewayEndpointsManifest> | ||
| <RunArguments>"$(_BlazorGatewayDll)" --environment Development --staticWebAssets "$(_GatewayStaticWebAssetsManifest)" --ClientApps:app:EndpointsManifest "$(_GatewayEndpointsManifest)" --ClientApps:app:PathPrefix ""</RunArguments> | ||
|
javiercn marked this conversation as resolved.
Resolved
|
||
| </PropertyGroup> | ||
| </Target> | ||
| </Project> | ||
|
Member
Author
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. Temporary until the SDK update flows to asp.net core |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| <!-- | ||
| Temporary targets file that adds a SPA fallback endpoint to the static web assets | ||
| endpoints manifest. This will be removed once the SDK ships StaticWebAssetSpaFallbackEnabled. | ||
| --> | ||
| <Project> | ||
| <PropertyGroup> | ||
| <GenerateStaticWebAssetsManifestDependsOn>$(GenerateStaticWebAssetsManifestDependsOn);_AddSpaFallbackEndpoint</GenerateStaticWebAssetsManifestDependsOn> | ||
| </PropertyGroup> | ||
|
|
||
| <Target Name="_AddSpaFallbackEndpoint"> | ||
| <ItemGroup> | ||
| <!-- Find the identity (uncompressed) index.html endpoint: Route == index.html, AssetFile not .gz/.br --> | ||
| <_SpaFallbackCandidate Include="@(StaticWebAssetEndpoint)" | ||
| Condition="'%(Identity)' == 'index.html' and !$([System.String]::Copy('%(AssetFile)').EndsWith('.gz')) and !$([System.String]::Copy('%(AssetFile)').EndsWith('.br'))" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup Condition="'@(_SpaFallbackCandidate)' != ''"> | ||
| <!-- Add a clone with route changed to the SPA catch-all pattern --> | ||
| <StaticWebAssetEndpoint Include="{**path:nonfile}" | ||
| AssetFile="%(_SpaFallbackCandidate.AssetFile)" | ||
| Selectors="%(_SpaFallbackCandidate.Selectors)" | ||
| EndpointProperties="%(_SpaFallbackCandidate.EndpointProperties)" | ||
| ResponseHeaders="%(_SpaFallbackCandidate.ResponseHeaders)" | ||
| Order="$([System.Int32]::MaxValue)" /> | ||
| </ItemGroup> | ||
| </Target> | ||
|
javiercn marked this conversation as resolved.
Resolved
|
||
| </Project> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.