I have an ASP.NET Core 2.1 Web Application set up with an Angular front-end (using VS default setup) that was configured to run over an HTTPS connection.
I ran the project initially, and it worked fine on https://localhost:44325. However, now, after editing my the .html and .ts files,the changes do not carry over. But when I run the server on http://localhost:4200, the changes carry over.
I want the changes to carry over on https://localhost:44325 since that is the port that my browser opens to when I run the application. How do I change this? Is it an npm issue? Is it in my angular app? Is it in Startup.cs?
Startup.cs
...
public void ConfigureDevelopmentServices(IServiceCollection services)
{
...
app.UseMvc(routes =>
{
routes.MapSpaFallbackRoute(
name: "spa-fallback",
defaults: new { controller = "Fallback", action = "Index" }
);
});
...
}
...
environment.ts
export const environment = {
production: false,
apiUrl: 'http://localhost:5000/api/'
};
After comparing to the default configuration of an Angular/Core 2 app, I found the differences that made the difference.
Startup.cs
public void ConfigureDevelopmentServices(IServiceCollection services)
{
...
services.AddSpaStaticFiles(configuration =>
{
configuration.RootPath = "ClientApp/dist";
});
...
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
...
app.UseSpaStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action=Index}/{id?}");
});
app.UseSpa(spa =>
{
// To learn more about options for serving an Angular SPA from ASP.NET Core,
// see https://go.microsoft.com/fwlink/?linkid=864501
spa.Options.SourcePath = "ClientApp";
if (env.IsDevelopment())
{
spa.UseProxyToSpaDevelopmentServer("http://localhost:4200");
//spa.UseAngularCliServer(npmScript: "start");
}
});
Environment.ts
apiUrl: 'https://localhost:44325/api/
(in Environment.prod.ts, this is 'api/')