|
2 | 2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | 3 |
|
4 | 4 | using Microsoft.AspNetCore.Builder; |
| 5 | +using Microsoft.AspNetCore.Hosting; |
5 | 6 | using Microsoft.AspNetCore.Http; |
6 | 7 | using Microsoft.Extensions.Configuration; |
7 | 8 | using Microsoft.Extensions.DependencyInjection; |
@@ -29,27 +30,29 @@ public static void Configure(IApplicationBuilder app, IConfiguration configurati |
29 | 30 |
|
30 | 31 | app.UseWebAssemblyDebugging(); |
31 | 32 |
|
32 | | - bool applyCopHeaders = configuration.GetValue<bool>("ApplyCopHeaders"); |
| 33 | + var webHostEnvironment = app.ApplicationServices.GetRequiredService<IWebHostEnvironment>(); |
| 34 | + var applyCopHeaders = configuration.GetValue<bool>("ApplyCopHeaders"); |
33 | 35 |
|
34 | | - if (applyCopHeaders) |
| 36 | + app.Use(async (ctx, next) => |
35 | 37 | { |
36 | | - app.Use(async (ctx, next) => |
| 38 | + if (ctx.Request.Path.StartsWithSegments("/_framework") && !ctx.Request.Path.StartsWithSegments("/_framework/blazor.server.js") && !ctx.Request.Path.StartsWithSegments("/_framework/blazor.web.js")) |
37 | 39 | { |
38 | | - if (ctx.Request.Path.StartsWithSegments("/_framework") && !ctx.Request.Path.StartsWithSegments("/_framework/blazor.server.js") && !ctx.Request.Path.StartsWithSegments("/_framework/blazor.web.js")) |
| 40 | + ctx.Response.Headers.Append("Blazor-Environment", webHostEnvironment.EnvironmentName); |
| 41 | + |
| 42 | + if (applyCopHeaders) |
39 | 43 | { |
40 | | - string fileExtension = Path.GetExtension(ctx.Request.Path); |
41 | | - if (string.Equals(fileExtension, ".js")) |
| 44 | + var fileExtension = Path.GetExtension(ctx.Request.Path); |
| 45 | + if (string.Equals(fileExtension, ".js", StringComparison.Ordinal)) |
42 | 46 | { |
43 | 47 | // Browser multi-threaded runtime requires cross-origin policy headers to enable SharedArrayBuffer. |
44 | 48 | ApplyCrossOriginPolicyHeaders(ctx); |
45 | 49 | } |
46 | 50 | } |
| 51 | + } |
47 | 52 |
|
48 | | - await next(ctx); |
49 | | - }); |
50 | | - } |
| 53 | + await next(ctx); |
| 54 | + }); |
51 | 55 |
|
52 | | - //app.UseBlazorFrameworkFiles(); |
53 | 56 | app.UseRouting(); |
54 | 57 |
|
55 | 58 | app.UseStaticFiles(new StaticFileOptions |
|
0 commit comments