I am building an Angular 2 app and using .NET Core and Webpack to compile my static resources into a dist folder. I am using a plugin that builds my index.html file and put
You can use code like below, but it only works when you put empty index.html in the root of wwwroot folder:
app.UseDefaultFiles();
// Serve wwwroot/dist as a root
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot\dist"))
});
RequestPath is empty by default so root path will show you index.html or default.html from wwwroot\dist folder.
UPDATE: There is easy and beautiful solution to handle this issue using WebRoot in Program.cs like below:
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseWebRoot(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "dist"))
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup()
.UseApplicationInsights()
.Build();
host.Run();
}
In Configure method of Startup.cs you just use:
app.UseDefaultFiles();
app.UseStaticFiles();