Asp.net 6.0 with angular 14 Run as Docker mode throws 404 - npm server does not start

Viewed 27

I have created a sample Asp.net 6.0 with Angular 14 application (using vs 2022). I had simply added docker support and run as docker.

When i do that, I am able to access the Dotnet controller's methods but the angular app won't load.

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["SampleAngularApp/NuGet.Config", "SampleAngularApp/"]
COPY ["SampleAngularApp/SampleAngularApp.csproj", "SampleAngularApp/"]
RUN dotnet restore "SampleAngularApp/SampleAngularApp.csproj"
COPY . .
WORKDIR "/src/SampleAngularApp"
RUN dotnet build "SampleAngularApp.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "SampleAngularApp.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "SampleAngularApp.dll"]

When i try to access asp.net controller - i am getting response

enter image description here

But the angular app which is supposed to run throws below 404 enter image description here

My program.cs looks as below

 public class Program
    {
        public static void Main(string[] args)
        {
            var builder = WebApplication.CreateBuilder(args);

            // Add services to the container.

            builder.Services.AddControllersWithViews();
            builder.Services.AddCors(c =>
            {
                c.AddPolicy("AllowOrigin", options =>
                {
                    options.AllowAnyOrigin()
                    .AllowAnyHeader()
                    .AllowAnyMethod();
                });
            });
            
            
            var app = builder.Build();

            // Configure the HTTP request pipeline.
            if (!app.Environment.IsDevelopment())
            {
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }
            app.UseCors("AllowOrigin");
            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseRouting();
            
            

            app.MapControllerRoute(
                name: "default",
                pattern: "{controller}/{action=Index}/{id?}");

            app.MapFallbackToFile("index.html");

            app.Run();
        }
    }

launchsettings.json as below

enter image description here

Angular package.json as below enter image description here

Please note the same code works well in IIS mode

0 Answers
Related