Setting up for Deployment

Building Angular App into Kestrel wit the API

Change output path in angular.json to

"outputPath": "../DatingApi.API/wwwroot"

Set up an ignore rule so we don't commit this folder.

To expose the SPA we need to add the following two lines to our Startup.cs

app.UseDefaultFiles();
app.UsesStaticFiles();

When refreshing, need to pass routing responsibility onto Angular.  Otherwise we get a page not found error.

This is done by adding a new FallbackController which is an MVC controller (base class Controller rather than ControllerBase), that does the following:

return PhysicalFile(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "index.html), "text/HTML");

And then in the startup endpoints, add:

endpoints.MapFallbackToController("Index", "Fallback");


Creating a Production Build  - Ahead of Time (AOT)

Using the --prod option on ng build does a lot of the things that you'd have to configure using the old WebPack with earlier versions of Angular.

Need to a apiUrl to the production environment in environment.prod.ts

apiUrl: 'api/'

Then build in production mode

ng build --prod

Configuring the database.

Use SqlLite connection string in appsettings.Development.json and SqlServer connection string in appsettings.json.

In Startup.cs, ASP.NET Core uses convention for calling the correct ConfigureServices method, so can set up a ConfigureDevelopmentServices and ConfigureProductionServices methods.

GOTCHA:  You cannot really have migrations that can target more than one time of database service.  So it's ok to develop V0 against SQLite, but once you want to move to SQL Server, you need to regenerate the migration and then stick to SQL Server variations from then on.


Comments

Popular posts from this blog

Understanding the technologies - Angular 8 and ASP.NET Web API Core 3

Bits and bobs