Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 11 additions & 0 deletions .autover/changes/fix-static-assets-non-production-env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"Projects": [
{
"Name": "Amazon.Lambda.TestTool",
"Type": "Patch",
"ChangelogMessages": [
"Fixed static assets (CSS, JS, BlazorMonaco) failing to load when ASPNETCORE_ENVIRONMENT or DOTNET_ENVIRONMENT is set to a non-Production value by always serving static files from the tool's install directory."
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,13 @@
<ItemGroup>
<None Include="../../README.md" Pack="true" PackagePath="\" />
</ItemGroup>


<!-- Ensure wwwroot content is copied to output directory -->
<ItemGroup>
Copy link
Copy Markdown
Collaborator Author

@GarrettBeatty GarrettBeatty Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the unit tests need this to pass. my guess is dotnet build does not auto copy the wwroot to the output directory.

However when i did the manual testing (as in the pr description), it seems like dotnet pack auto copy everything which is why this change wasn't needed then. But when i ran the tests i had to add in b559dd5

<Content Update="wwwroot\**\*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,8 @@ public static TestToolProcess Startup(RunCommandSettings settings, CancellationT
builder.Services.AddHttpContextAccessor();

var wwwrootPath = Path.Combine(AppContext.BaseDirectory, "wwwroot");
if (builder.Environment.IsProduction())
{
builder.Services.AddSingleton<IFileProvider>(new PhysicalFileProvider(wwwrootPath));
}
var wwwrootFileProvider = new PhysicalFileProvider(wwwrootPath);
builder.Services.AddSingleton<IFileProvider>(wwwrootFileProvider);
builder.Services.AddSingleton<IDirectoryManager, DirectoryManager>();

var serviceHttp = $"http://{settings.LambdaEmulatorHost}:{settings.LambdaEmulatorPort}";
Expand All @@ -87,20 +85,21 @@ public static TestToolProcess Startup(RunCommandSettings settings, CancellationT

var app = builder.Build();

if (app.Environment.IsProduction())
{
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(wwwrootPath)
});
}
else
if (!app.Environment.IsProduction())
{
// nosemgrep: csharp.lang.security.stacktrace-disclosure.stacktrace-disclosure
app.UseDeveloperExceptionPage();
app.UseStaticFiles();
}

// Always use the explicit file provider to serve static files from the tool's install
// directory. Without this, non-Production environments attempt to use the static web
// assets manifest which contains absolute paths from the build machine and will fail
// when running as an installed global tool on a different machine.
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = wwwrootFileProvider
});

app.UseAntiforgery();

app.MapRazorComponents<App>()
Expand Down
Loading