Should be simple scenario I imagine; have
Want to deploy on Windows Server with IIS have read through: Host ASP.NET Core on Windows with IIS
Want to with reccomended default In-process hosting model
But how to combine the Angular SPA and .net core web api? I can get the web api running fine under a new site in IIS serving files from publish output but where to put my SPA?
api/blah
become alias/api/blah
I see if using the Angular template to create solution it creates a ClientApps/dist
dir, maybe could recreate the project with that template then dump the Angular build in that dir on deploy (since Angular project developed in separate repo).
// In production, the Angular files will be served from this directory
services.AddSpaStaticFiles(configuration =>
{
configuration.RootPath = "ClientApp/dist";
});
Seeing this question is already a month old. Hopefully you have found a solution. @JokiesDing comment is pretty much on point.
My approach with development and deployment is to have the SPA application inside the Web API project and utilize Microsoft.AspNetCore.SpaServices.Extensions
. Here are the steps:
Microsoft.AspNetCore.SpaServices.Extensions
from NugetStartup.cs
and add the extension methodspublic void ConfigureServices(IServiceCollection services)
{
//... whatever you have in your ConfigureServices method...
//add this
services.AddSpaStaticFiles(configuration =>
{
configuration.RootPath = "ClientApp/dist";
});
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
//... whatever you have in your configure method...
//add this
app.UseStaticFiles();
if (!env.IsDevelopment())
{
app.UseSpaStaticFiles();
}
app.UseSpa(spa =>
{
// To learn more about options for serving an Angular SPA
// see https://go.microsoft.com/fwlink/?linkid=864501
spa.Options.SourcePath = "ClientApp";
if (env.IsDevelopment())
{
spa.UseAngularCliServer(npmScript: "start");
}
});
}
npm run start
everytime you build, you can point the webapi to the SPA dev server. if (env.IsDevelopment())
{
spa.UseProxyToSpaDevelopmentServer("http://localhost:4200");
}
For Reference see this starter template https://github.com/jasontaylordev/CleanArchitecture
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