Skip to content

Commit

Permalink
[Blazor] Adds compresion support for all assets in an application (#5…
Browse files Browse the repository at this point in the history
…5558)

Adds a new MapStaticAssetEndpoints routerware that reads a manifest generated at build / publish time and maps the endpoints defined in the manifest to the files in the application wwwroot folder.

Adds a MatcherPolicy to perform content negotiation based on the Accept-Encoding header. Compressed resources contain a ContentEncoding attribute in their metadata that is used to filter out the compressed asset to serve to the client based on the Accept-Encoding header.

The content encoding has an associated Quality value that represents the 'server preference' for the encoding. We always use the client preference and only rely on the server preference to break ties.

This process is completely driven by de the build and transparent to the runtime, if in the future we add support for zstd, sbr, etc. we don't need to change the runtime.

The logic for serving static files is borrowed from the static files middleware, with simplifications and additions. I've ported the relevant tests to ensure a high degree of compatibility.

The logic is new "routerware" instead of directly baked into the static files middleware because we do not want to pollute that middleware with more complex logic and we are going to be layering fingerprinting on top of this change, which will register more endpoints that will include more custom headers, which is not suitable for the static files middleware.

During development we wrap the endpoints we generate to support changing the files while the app is running (we recompute some of the values on the fly and also register a fallback route that matches file patterns to serve new files added while the app is running).

The build/publish process computes all the required information about the assets that is used to emit the response. The ETag and Last-Modified values are computed using the Base64(SHA256) hash of the content and the LastWrite on the file at build/publish time.
  • Loading branch information
javiercn authored May 13, 2024
1 parent 0b59b2c commit 51838a2
Show file tree
Hide file tree
Showing 68 changed files with 3,817 additions and 50 deletions.
41 changes: 41 additions & 0 deletions AspNetCore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -1806,6 +1806,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNetCore.OpenAp
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KeyManagementSimulator", "src\DataProtection\samples\KeyManagementSimulator\KeyManagementSimulator.csproj", "{5B5F86CC-3598-463C-9F9B-F78FBB6642F4}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "StaticAssets", "StaticAssets", "{274100A5-5B2D-4EA2-AC42-A62257FC6BDC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.StaticAssets", "src\StaticAssets\src\Microsoft.AspNetCore.StaticAssets.csproj", "{4D8DE54A-4F32-4881-B07B-DDC79619E573}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.StaticAssets.Tests", "src\StaticAssets\test\Microsoft.AspNetCore.StaticAssets.Tests.csproj", "{9536C284-65B4-4884-BB50-06D629095C3E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -10903,6 +10909,38 @@ Global
{5B5F86CC-3598-463C-9F9B-F78FBB6642F4}.Release|x64.Build.0 = Release|Any CPU
{5B5F86CC-3598-463C-9F9B-F78FBB6642F4}.Release|x86.ActiveCfg = Release|Any CPU
{5B5F86CC-3598-463C-9F9B-F78FBB6642F4}.Release|x86.Build.0 = Release|Any CPU
{4D8DE54A-4F32-4881-B07B-DDC79619E573}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4D8DE54A-4F32-4881-B07B-DDC79619E573}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4D8DE54A-4F32-4881-B07B-DDC79619E573}.Debug|arm64.ActiveCfg = Debug|Any CPU
{4D8DE54A-4F32-4881-B07B-DDC79619E573}.Debug|arm64.Build.0 = Debug|Any CPU
{4D8DE54A-4F32-4881-B07B-DDC79619E573}.Debug|x64.ActiveCfg = Debug|Any CPU
{4D8DE54A-4F32-4881-B07B-DDC79619E573}.Debug|x64.Build.0 = Debug|Any CPU
{4D8DE54A-4F32-4881-B07B-DDC79619E573}.Debug|x86.ActiveCfg = Debug|Any CPU
{4D8DE54A-4F32-4881-B07B-DDC79619E573}.Debug|x86.Build.0 = Debug|Any CPU
{4D8DE54A-4F32-4881-B07B-DDC79619E573}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4D8DE54A-4F32-4881-B07B-DDC79619E573}.Release|Any CPU.Build.0 = Release|Any CPU
{4D8DE54A-4F32-4881-B07B-DDC79619E573}.Release|arm64.ActiveCfg = Release|Any CPU
{4D8DE54A-4F32-4881-B07B-DDC79619E573}.Release|arm64.Build.0 = Release|Any CPU
{4D8DE54A-4F32-4881-B07B-DDC79619E573}.Release|x64.ActiveCfg = Release|Any CPU
{4D8DE54A-4F32-4881-B07B-DDC79619E573}.Release|x64.Build.0 = Release|Any CPU
{4D8DE54A-4F32-4881-B07B-DDC79619E573}.Release|x86.ActiveCfg = Release|Any CPU
{4D8DE54A-4F32-4881-B07B-DDC79619E573}.Release|x86.Build.0 = Release|Any CPU
{9536C284-65B4-4884-BB50-06D629095C3E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9536C284-65B4-4884-BB50-06D629095C3E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9536C284-65B4-4884-BB50-06D629095C3E}.Debug|arm64.ActiveCfg = Debug|Any CPU
{9536C284-65B4-4884-BB50-06D629095C3E}.Debug|arm64.Build.0 = Debug|Any CPU
{9536C284-65B4-4884-BB50-06D629095C3E}.Debug|x64.ActiveCfg = Debug|Any CPU
{9536C284-65B4-4884-BB50-06D629095C3E}.Debug|x64.Build.0 = Debug|Any CPU
{9536C284-65B4-4884-BB50-06D629095C3E}.Debug|x86.ActiveCfg = Debug|Any CPU
{9536C284-65B4-4884-BB50-06D629095C3E}.Debug|x86.Build.0 = Debug|Any CPU
{9536C284-65B4-4884-BB50-06D629095C3E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9536C284-65B4-4884-BB50-06D629095C3E}.Release|Any CPU.Build.0 = Release|Any CPU
{9536C284-65B4-4884-BB50-06D629095C3E}.Release|arm64.ActiveCfg = Release|Any CPU
{9536C284-65B4-4884-BB50-06D629095C3E}.Release|arm64.Build.0 = Release|Any CPU
{9536C284-65B4-4884-BB50-06D629095C3E}.Release|x64.ActiveCfg = Release|Any CPU
{9536C284-65B4-4884-BB50-06D629095C3E}.Release|x64.Build.0 = Release|Any CPU
{9536C284-65B4-4884-BB50-06D629095C3E}.Release|x86.ActiveCfg = Release|Any CPU
{9536C284-65B4-4884-BB50-06D629095C3E}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -11795,6 +11833,9 @@ Global
{9DC6B242-457B-4767-A84B-C3D23B76C642} = {2299CCD8-8F9C-4F2B-A633-9BF4DA81022B}
{D53F0EF7-0CDC-49B4-AA2D-229901B0A734} = {9DC6B242-457B-4767-A84B-C3D23B76C642}
{5B5F86CC-3598-463C-9F9B-F78FBB6642F4} = {8275510E-0E6C-45A8-99DF-4F106BC7F075}
{274100A5-5B2D-4EA2-AC42-A62257FC6BDC} = {017429CC-C5FB-48B4-9C46-034E29EE2F06}
{4D8DE54A-4F32-4881-B07B-DDC79619E573} = {274100A5-5B2D-4EA2-AC42-A62257FC6BDC}
{9536C284-65B4-4884-BB50-06D629095C3E} = {274100A5-5B2D-4EA2-AC42-A62257FC6BDC}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3E8720B3-DBDD-498C-B383-2CC32A054E8F}
Expand Down
2 changes: 2 additions & 0 deletions eng/Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@
$(RepoRoot)src\Mvc\**\*.*proj;
$(RepoRoot)src\Azure\**\*.*proj;
$(RepoRoot)src\SignalR\**\*.csproj;
$(RepoRoot)src\StaticAssets\**\*.csproj;
$(RepoRoot)src\Components\**\*.csproj;
$(RepoRoot)src\Analyzers\**\*.csproj;
$(RepoRoot)src\FileProviders\**\*.csproj;
Expand Down Expand Up @@ -219,6 +220,7 @@
$(RepoRoot)src\Mvc\**\src\*.csproj;
$(RepoRoot)src\Azure\**\src\*.csproj;
$(RepoRoot)src\SignalR\**\src\*.csproj;
$(RepoRoot)src\StaticAssets\src\*.csproj;
$(RepoRoot)src\Components\**\src\*.csproj;
$(RepoRoot)src\FileProviders\**\src\*.csproj;
$(RepoRoot)src\Configuration.KeyPerFile\**\src\*.csproj;
Expand Down
1 change: 1 addition & 0 deletions eng/ProjectReferences.props
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
<ProjectReferenceProvider Include="Microsoft.AspNetCore.SignalR" ProjectPath="$(RepoRoot)src\SignalR\server\SignalR\src\Microsoft.AspNetCore.SignalR.csproj" />
<ProjectReferenceProvider Include="Microsoft.AspNetCore.SignalR.Specification.Tests" ProjectPath="$(RepoRoot)src\SignalR\server\Specification.Tests\src\Microsoft.AspNetCore.SignalR.Specification.Tests.csproj" />
<ProjectReferenceProvider Include="Microsoft.AspNetCore.SignalR.StackExchangeRedis" ProjectPath="$(RepoRoot)src\SignalR\server\StackExchangeRedis\src\Microsoft.AspNetCore.SignalR.StackExchangeRedis.csproj" />
<ProjectReferenceProvider Include="Microsoft.AspNetCore.StaticAssets" ProjectPath="$(RepoRoot)src\StaticAssets\src\Microsoft.AspNetCore.StaticAssets.csproj" />
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Components.Authorization" ProjectPath="$(RepoRoot)src\Components\Authorization\src\Microsoft.AspNetCore.Components.Authorization.csproj" />
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Components" ProjectPath="$(RepoRoot)src\Components\Components\src\Microsoft.AspNetCore.Components.csproj" />
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Components.CustomElements" ProjectPath="$(RepoRoot)src\Components\CustomElements\src\Microsoft.AspNetCore.Components.CustomElements.csproj" />
Expand Down
1 change: 1 addition & 0 deletions eng/SharedFramework.Local.props
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
<AspNetCoreAppReference Include="Microsoft.AspNetCore.Http.Connections" />
<AspNetCoreAppReference Include="Microsoft.AspNetCore.SignalR.Core" />
<AspNetCoreAppReference Include="Microsoft.AspNetCore.SignalR" />
<AspNetCoreAppReference Include="Microsoft.AspNetCore.StaticAssets" />
<AspNetCoreAppReference Include="Microsoft.AspNetCore.Components.Endpoints" />
<AspNetCoreAppReference Include="Microsoft.AspNetCore.Components.Server" />
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions eng/ShippingAssemblies.props
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
<AspNetCoreShippingAssembly Include="Microsoft.AspNetCore.SignalR.Common" />
<AspNetCoreShippingAssembly Include="Microsoft.AspNetCore.SignalR.Core" />
<AspNetCoreShippingAssembly Include="Microsoft.AspNetCore.SignalR" />
<AspNetCoreShippingAssembly Include="Microsoft.AspNetCore.StaticAssets" />
<AspNetCoreShippingAssembly Include="Microsoft.AspNetCore.Components.Authorization" />
<AspNetCoreShippingAssembly Include="Microsoft.AspNetCore.Components" />
<AspNetCoreShippingAssembly Include="Microsoft.AspNetCore.Components.Endpoints" />
Expand Down
1 change: 1 addition & 0 deletions eng/TrimmableProjects.props
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
<TrimmableProject Include="Microsoft.AspNetCore.Http.Connections.Common" />
<TrimmableProject Include="Microsoft.AspNetCore.Http.Connections" />
<TrimmableProject Include="Microsoft.AspNetCore.SignalR.Common" />
<TrimmableProject Include="Microsoft.AspNetCore.StaticAssets" />
<TrimmableProject Include="Microsoft.AspNetCore.Components.Authorization" />
<TrimmableProject Include="Microsoft.AspNetCore.Components" />
<TrimmableProject Include="Microsoft.AspNetCore.Components.CustomElements" />
Expand Down
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"sdk": {
"version": "9.0.100-preview.5.24229.2"
"version": "9.0.100-preview.5.24253.17"
},
"tools": {
"dotnet": "9.0.100-preview.5.24229.2",
"dotnet": "9.0.100-preview.5.24253.17",
"runtimes": {
"dotnet/x86": [
"$(MicrosoftNETCoreBrowserDebugHostTransportVersion)"
Expand Down
5 changes: 5 additions & 0 deletions src/Components/Components.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
"src\\Components\\WebAssembly\\Authentication.Msal\\src\\Microsoft.Authentication.WebAssembly.Msal.csproj",
"src\\Components\\WebAssembly\\DevServer\\src\\Microsoft.AspNetCore.Components.WebAssembly.DevServer.csproj",
"src\\Components\\WebAssembly\\JSInterop\\src\\Microsoft.JSInterop.WebAssembly.csproj",
"src\\Components\\WebAssembly\\Samples\\HostedBlazorWebassemblyApp\\Client\\HostedBlazorWebassemblyApp.Client.csproj",
"src\\Components\\WebAssembly\\Samples\\HostedBlazorWebassemblyApp\\Server\\HostedBlazorWebassemblyApp.Server.csproj",
"src\\Components\\WebAssembly\\Samples\\HostedBlazorWebassemblyApp\\Shared\\HostedBlazorWebassemblyApp.Shared.csproj",
"src\\Components\\WebAssembly\\Server\\src\\Microsoft.AspNetCore.Components.WebAssembly.Server.csproj",
"src\\Components\\WebAssembly\\Server\\test\\Microsoft.AspNetCore.Components.WebAssembly.Server.Tests.csproj",
"src\\Components\\WebAssembly\\WebAssembly.Authentication\\src\\Microsoft.AspNetCore.Components.WebAssembly.Authentication.csproj",
Expand Down Expand Up @@ -145,6 +148,8 @@
"src\\SignalR\\common\\SignalR.Common\\src\\Microsoft.AspNetCore.SignalR.Common.csproj",
"src\\SignalR\\server\\Core\\src\\Microsoft.AspNetCore.SignalR.Core.csproj",
"src\\SignalR\\server\\SignalR\\src\\Microsoft.AspNetCore.SignalR.csproj",
"src\\StaticAssets\\src\\Microsoft.AspNetCore.StaticAssets.csproj",
"src\\StaticAssets\\test\\Microsoft.AspNetCore.StaticAssets.Tests.csproj",
"src\\Testing\\src\\Microsoft.AspNetCore.InternalTesting.csproj",
"src\\WebEncoders\\src\\Microsoft.Extensions.WebEncoders.csproj"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Routing;

namespace Microsoft.AspNetCore.Components.Endpoints.Infrastructure;

Expand All @@ -19,5 +20,11 @@ public static void AddRenderMode(RazorComponentsEndpointConventionBuilder builde
{
builder.AddRenderMode(renderMode);
}

/// <summary>
/// This method is not recommended for use outside of the Blazor framework.
/// </summary>
/// <param name="builder"></param>
public static IEndpointRouteBuilder GetEndpointRouteBuilder(RazorComponentsEndpointConventionBuilder builder) => builder.EndpointRouteBuilder;
}

Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,20 @@ internal class RazorComponentEndpointDataSource<[DynamicallyAccessedMembers(Comp
public RazorComponentEndpointDataSource(
ComponentApplicationBuilder builder,
IEnumerable<RenderModeEndpointProvider> renderModeEndpointProviders,
IApplicationBuilder applicationBuilder,
IEndpointRouteBuilder endpointRouteBuilder,
RazorComponentEndpointFactory factory,
HotReloadService? hotReloadService = null)
{
_builder = builder;
_applicationBuilder = applicationBuilder;
_applicationBuilder = endpointRouteBuilder.CreateApplicationBuilder();
_renderModeEndpointProviders = renderModeEndpointProviders.ToArray();
_factory = factory;
_hotReloadService = hotReloadService;
HotReloadService.ClearCacheEvent += OnHotReloadClearCache;
DefaultBuilder = new RazorComponentsEndpointConventionBuilder(
_lock,
builder,
endpointRouteBuilder,
_options,
_conventions,
_finallyConventions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ public RazorComponentEndpointDataSourceFactory(
var builder = ComponentApplicationBuilder.GetBuilder<TRootComponent>() ??
DefaultRazorComponentApplication<TRootComponent>.Instance.GetBuilder();

return new RazorComponentEndpointDataSource<TRootComponent>(builder, _providers, endpoints.CreateApplicationBuilder(), _factory, _hotReloadService);
return new RazorComponentEndpointDataSource<TRootComponent>(builder, _providers, endpoints, _factory, _hotReloadService);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Discovery;
using Microsoft.AspNetCore.Components.Endpoints;
using Microsoft.AspNetCore.Routing;

namespace Microsoft.AspNetCore.Builder;

Expand All @@ -14,19 +15,22 @@ public sealed class RazorComponentsEndpointConventionBuilder : IEndpointConventi
{
private readonly object _lock;
private readonly ComponentApplicationBuilder _builder;
private readonly IEndpointRouteBuilder _endpointRouteBuilder;
private readonly RazorComponentDataSourceOptions _options;
private readonly List<Action<EndpointBuilder>> _conventions;
private readonly List<Action<EndpointBuilder>> _finallyConventions;

internal RazorComponentsEndpointConventionBuilder(
object @lock,
ComponentApplicationBuilder builder,
IEndpointRouteBuilder endpointRouteBuilder,
RazorComponentDataSourceOptions options,
List<Action<EndpointBuilder>> conventions,
List<Action<EndpointBuilder>> finallyConventions)
{
_lock = @lock;
_builder = builder;
_endpointRouteBuilder = endpointRouteBuilder;
_options = options;
_conventions = conventions;
_finallyConventions = finallyConventions;
Expand All @@ -37,6 +41,8 @@ internal RazorComponentsEndpointConventionBuilder(
/// </summary>
internal ComponentApplicationBuilder ApplicationBuilder => _builder;

internal IEndpointRouteBuilder EndpointRouteBuilder => _endpointRouteBuilder;

/// <inheritdoc/>
public void Add(Action<EndpointBuilder> convention)
{
Expand Down
1 change: 1 addition & 0 deletions src/Components/Endpoints/src/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#nullable enable
Microsoft.AspNetCore.Components.Routing.RazorComponentsEndpointHttpContextExtensions
static Microsoft.AspNetCore.Components.Endpoints.Infrastructure.ComponentEndpointConventionBuilderHelper.GetEndpointRouteBuilder(Microsoft.AspNetCore.Builder.RazorComponentsEndpointConventionBuilder! builder) -> Microsoft.AspNetCore.Routing.IEndpointRouteBuilder!
static Microsoft.AspNetCore.Components.Routing.RazorComponentsEndpointHttpContextExtensions.AcceptsInteractiveRouting(this Microsoft.AspNetCore.Http.HttpContext! context) -> bool
16 changes: 15 additions & 1 deletion src/Components/Endpoints/test/HotReloadServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ private static RazorComponentEndpointDataSource<TComponent> CreateDataSource<TCo
var result = new RazorComponentEndpointDataSource<TComponent>(
builder,
new[] { new MockEndpointProvider() },
new ApplicationBuilder(services),
new TestEndpointRouteBuilder(services),
new RazorComponentEndpointFactory(),
new HotReloadService() { MetadataUpdateSupported = true });

Expand Down Expand Up @@ -256,4 +256,18 @@ public override IEnumerable<RouteEndpointBuilder> GetEndpointBuilders(IComponent

public override bool Supports(IComponentRenderMode renderMode) => true;
}

private class TestEndpointRouteBuilder : IEndpointRouteBuilder
{
private IServiceProvider _serviceProvider;
private List<EndpointDataSource> _dataSources = new();

public TestEndpointRouteBuilder(IServiceProvider serviceProvider) => _serviceProvider = serviceProvider;

public IServiceProvider ServiceProvider => _serviceProvider;

public ICollection<EndpointDataSource> DataSources => _dataSources;

public IApplicationBuilder CreateApplicationBuilder() => new ApplicationBuilder(_serviceProvider);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ private RazorComponentEndpointDataSource<TComponent> CreateDataSource<TComponent
var result = new RazorComponentEndpointDataSource<TComponent>(
builder ?? DefaultRazorComponentApplication<TComponent>.Instance.GetBuilder(),
services?.GetService<IEnumerable<RenderModeEndpointProvider>>() ?? Enumerable.Empty<RenderModeEndpointProvider>(),
new ApplicationBuilder(services ?? new ServiceCollection().BuildServiceProvider()),
new TestEndpointRouteBuilder(services ?? new ServiceCollection().BuildServiceProvider()),
new RazorComponentEndpointFactory(),
new HotReloadService() { MetadataUpdateSupported = true });

Expand Down Expand Up @@ -277,6 +277,20 @@ public override IEnumerable<RouteEndpointBuilder> GetEndpointBuilders(IComponent

public override bool Supports(IComponentRenderMode renderMode) => renderMode is InteractiveWebAssemblyRenderMode or InteractiveAutoRenderMode;
}

private class TestEndpointRouteBuilder : IEndpointRouteBuilder
{
private IServiceProvider _serviceProvider;
private List<EndpointDataSource> _dataSources = new();

public TestEndpointRouteBuilder(IServiceProvider serviceProvider) => _serviceProvider = serviceProvider;

public IServiceProvider ServiceProvider => _serviceProvider;

public ICollection<EndpointDataSource> DataSources => _dataSources;

public IApplicationBuilder CreateApplicationBuilder() => new ApplicationBuilder(_serviceProvider);
}
}

public class App : IComponent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<Reference Include="Microsoft.AspNetCore.Components.Server" />
<Reference Include="Microsoft.AspNetCore.HttpsPolicy" />
<Reference Include="Microsoft.AspNetCore.StaticFiles" />
<Reference Include="Microsoft.AspNetCore.StaticAssets" />
<Reference Include="Microsoft.AspNetCore.Mvc" />
</ItemGroup>

Expand Down
1 change: 1 addition & 0 deletions src/Components/Samples/BlazorUnitedApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
app.UseStaticFiles();
app.UseAntiforgery();

app.MapStaticAssets();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<Reference Include="Microsoft.AspNetCore" />
<Reference Include="Microsoft.AspNetCore.HttpsPolicy" />
<Reference Include="Microsoft.AspNetCore.Mvc" />
<Reference Include="Microsoft.AspNetCore.StaticAssets" />
<Reference Include="Microsoft.Extensions.Hosting" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using HostedBlazorWebassemblyApp.Server.Data;
using HostedBlazorWebassemblyApp.Shared;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Components.WebAssembly.Server;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.Extensions.Configuration;
Expand Down Expand Up @@ -48,16 +49,14 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
}

app.UseHttpsRedirection();
app.UseBlazorFrameworkFiles();
app.UseStaticFiles();

app.UseRouting();

app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
endpoints.MapControllers();
//endpoints.MapFallbackToFile("index.html");
endpoints.MapStaticAssets();
endpoints.MapFallbackToPage("/_Host");
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,11 @@ public sealed class WebAssemblyComponentsEndpointOptions
/// information, see <see href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer#security_requirements" />.
/// </summary>
public bool ServeMultithreadingHeaders { get; set; }

/// <summary>
/// Gets or sets the <see cref="string"/> that determines the static assets manifest path mapped to this app.
/// </summary>
public string? StaticAssetsManifestPath { get; set; }

internal bool ConventionsApplied { get; set; }
}
Loading

0 comments on commit 51838a2

Please sign in to comment.