I am trying to deploy an Angular 7
application with .NET Core
using Kestrel
using the FileProvider
extension.
I have created the angular app , i have ng build
it and i copied the files inside dist
.NET
Porject.
Startup
public void Configure(IApplicationBuilder app, IHostingEnvironment env) {
string jsFolderName = "myroot";
string prodRoot =Path.Combine(AppDomain.CurrentDomain.BaseDirectory,jsFolderName);
string debugRoot =Path.Combine(Directory.GetCurrentDirectory(),jsFolderName);
var isDev=env.IsDevelopment();
DefaultFilesOptions options = new DefaultFilesOptions();
options.DefaultFileNames.Clear();
options.DefaultFileNames.Add("/myroot/index.html");
app.UseDefaultFiles(options);
app.UseStaticFiles();
app.UseStaticFiles(new StaticFileOptions() {
FileProvider = new PhysicalFileProvider(isDev?debugRoot:prodRoot),
RequestPath = "/app"
});
if (env.IsDevelopment()) {
app.UseDeveloperExceptionPage();
} else {
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseMvc();
}
P.S My myroot
folder is right in the root of the project.
I do not know how to feed the first page (entrypoint) of the angular
app which is index.html
.
As suggested by @Simonare in the comment, the best way is to use official Angular template.
But if you want to serve the static files only, you could do as below :
DefaultFilesOptions
withFileProvider
andRequestPath
.Because the path of app is
https://yourhost:port/app
, you also need to change the base path within theindex.html
, so that browser will load all assets (e.g. js, css, img files) relative to current path. The original base of/src/index.html
is/
:Note we need :
<base href="/">
to<base href="/app">
<base href="">