I am having a problem with ASP.NET Core not serving static files properly. I have parts of my app in node_modules under wwwroot. For the most part all files work, but there are exceptions. *.js.map files are routed to MVC controller, serving my MVC pages instead of actual files. As a result, I get errors in the browser such as
Failed to parse SourceMap: http://localhost:5000/node_modules/bootstrap/bootstrap.min.css.map
Going the same route, my web fonts, such as the one includes with Bootstrap are also not served properly, being also handled by MVC middleware instead of static files middleware. It seems that all files that reside in node_modules should be routed to my static files middleware, which is not happening. Thanks.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseStaticFiles(); app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider(Path.Combine(env.WebRootPath, @"node_modules")), RequestPath = new PathString("/node_modules"), ServeUnknownFileTypes = true }); app.UseMvc(config => { config.MapRoute("Default", "{controller}/{action}/{id?}", new { controller = "Home", action = "Index" }); config.MapRoute("AngularDeepLinkingRoute", "{*url}", new { controller = "Home", action = "Index" }); }); }
The problem was that if a static file, such as *.js.map file is missing, static files middleware does not handle the request, and it goes to MVC middleware.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With