featherhttp / framework

A lightweight low ceremony API for web services.
MIT License
808 stars 37 forks source link

IWebHostEnvironment missing static assets from referenced projects #26

Closed stevebelskie closed 4 years ago

stevebelskie commented 4 years ago

To try out featherhttp and see if it would work with Blazor WebAssembly, I created a new project using the Blazor Wasm template for 3.2 RC with an Asp.NET Core host. I just deleted the startup for the server host and changed Program.cs to following:

            builder.Services.AddControllersWithViews();
            builder.Services.AddRazorPages();
            var app = builder.Build();

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

            app.MapRazorPages();
            app.MapControllers();
            app.MapFallbackToFile("index.html");

            app.Run();

Running the program results in a 404. Stepping into app.UseBlazorFrameworkFiles shows that the webHostEnvironment has a NullFileProvider instead of the CompositeFileProvider (with the path to the static content for the referenced Blazor client project) that I would expect and which is correctly populated if you use the template as is.

Interestingly (or maybe not), calling GetServices returns two entires, one of which seems to have the correct WebRootFileProvider. This is not the environment, however, resolved inside app.UseBlazorFrameworkFiles.

Is this the expected behavior? I attempted to work through the source here, and for the standard WebHostBuilder to see what was happening, but couldn't quite pinpoint where they diverge. Is this possibly related to the changes for #19 and/or the use of the deferred host?

I can provide more information/clarification if needed.

Thanks!

davidfowl commented 4 years ago

Hmm, will look into this.

maxild commented 3 years ago

@davidfowl Is this issue resolved?

I have the exact same issue. Had to change the "server" into standard StartUp class to setup services and middleware, before I could serve blazor wasm spa-app from the server through kestrel (basically copying the setup of dotnet new blazorwasm --hosted -o blazorwasmhosted in the CLI). The app is the React+TodoApi enhanced with alternate Blazor client.

I am running 0.1.82-alpha.g7c8518a220

Happy to provide more info, but wanted to find out, if this is to be expected first.

maxild commented 3 years ago

The issue is unchanged: app.UseBlazorFrameworkFiles will not corrrectly setup static files, because CreateStaticFilesOptions get passed a NullFileProvider. When instead using the normal StartUp pattern to bootstrap the web app, a CompositeFileProvider is passed to CreateStaticFilesOptions....and the UseBlazorFrameworkFiles can do its job and enable the serving of the "blazor environment" to the browser