Asp.net core 2.1 - How to serve multiple angular apps?
Well, I finally solved it and it works like this:
public void ConfigureServices(IServiceCollection services)
{
...
services.AddSpaStaticFiles();
...
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
...
app.UseSpaStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot"))
});
app.UseMvc();
app.Map("/app", client =>
{
client.UseSpa(spa =>
{
spa.Options.SourcePath = "wwwroot/app";
spa.Options.DefaultPageStaticFileOptions = new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/app"))
};
});
}).Map("/admin", admin =>
{
admin.UseSpa(spa =>
{
spa.Options.SourcePath = "wwwroot/admin";
spa.Options.DefaultPageStaticFileOptions = new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/admin"))
};
});
});
}
Also, don't forget to go into the index.html
file of each app and set the base
tag accordingly like this:
//for the client application:
<base href="/app/">
//for the admin application
<base href="/admin/">