Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions src/Components/WebAssembly/DevServer/src/Server/Startup.cs
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.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -29,27 +30,29 @@ public static void Configure(IApplicationBuilder app, IConfiguration configurati

app.UseWebAssemblyDebugging();

bool applyCopHeaders = configuration.GetValue<bool>("ApplyCopHeaders");
var webHostEnvironment = app.ApplicationServices.GetRequiredService<IWebHostEnvironment>();
var applyCopHeaders = configuration.GetValue<bool>("ApplyCopHeaders");

if (applyCopHeaders)
app.Use(async (ctx, next) =>
{
app.Use(async (ctx, next) =>
if (ctx.Request.Path.StartsWithSegments("/_framework") && !ctx.Request.Path.StartsWithSegments("/_framework/blazor.server.js") && !ctx.Request.Path.StartsWithSegments("/_framework/blazor.web.js"))
{
if (ctx.Request.Path.StartsWithSegments("/_framework") && !ctx.Request.Path.StartsWithSegments("/_framework/blazor.server.js") && !ctx.Request.Path.StartsWithSegments("/_framework/blazor.web.js"))
ctx.Response.Headers.Append("Blazor-Environment", webHostEnvironment.EnvironmentName);

if (applyCopHeaders)
{
string fileExtension = Path.GetExtension(ctx.Request.Path);
if (string.Equals(fileExtension, ".js"))
var fileExtension = Path.GetExtension(ctx.Request.Path);
if (string.Equals(fileExtension, ".js", StringComparison.Ordinal))
{
// Browser multi-threaded runtime requires cross-origin policy headers to enable SharedArrayBuffer.
ApplyCrossOriginPolicyHeaders(ctx);
}
}
}

await next(ctx);
});
}
await next(ctx);
});

//app.UseBlazorFrameworkFiles();
app.UseRouting();

app.UseStaticFiles(new StaticFileOptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public void WebAssemblyConfiguration_Works()
// Verify values from the default 'appsettings.json' are read.
Browser.Equal("Default key1-value", () => _appElement.FindElement(By.Id("key1")).Text);

// Verify that the dev server always correctly serves the 'Blazor-Environment: Development' header.
Browser.Equal("Development", () => _appElement.FindElement(By.Id("environment")).Text);

if (_serverFixture.TestTrimmedOrMultithreadingApps)
{
// Verify values overriden by an environment specific 'appsettings.$(Environment).json are read
Expand Down
Loading