Home > Software design >  ASP.NET 6 API deployed to Heroku returning status 404 on any route
ASP.NET 6 API deployed to Heroku returning status 404 on any route

Time:06-17

I have an ASP.NET 6 API running in a docker container. When i run the Dockerfile locally everything works perfectly. I am currently trying to host this Dockerfile on heroku.

I have followed the instruction and successfully deployed the image. However, I cannot reach any page or call any controller. By default loading it up should open up /swagger/index.html, but all I get is a 404 status.

This is the Dockerfile

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 ["Mongo_API.csproj", "."]
RUN dotnet restore "./Mongo_API.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "Mongo_API.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Mongo_API.csproj" -c Release -o /app/publish

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

CMD ASPNETCORE_URLS=http://*:$PORT dotnet Mongo_API.dll

And these are the logs from Heroku

2022-06-14T20:26:29.665971 00:00 heroku[router]: at=info method=GET path="/index.html" host={myapp}.herokuapp.com request_id=84697615-6cf3-4eef-9296-6febd71b2016 fwd="ip" dyno=web.1 connect=0ms service=429ms status=404 bytes=118 protocol=https

2022-06-14T20:26:37.314043 00:00 heroku[router]: at=info method=GET path="/swagger/index.html" host={myapp}.herokuapp.com request_id=85129334-7ac1-4bbb-a797-5c802a24567e fwd="ip" dyno=web.1 connect=0ms service=1ms status=404 bytes=118 protocol=https

2022-06-14T20:26:45.855736 00:00 heroku[router]: at=info method=GET path="/" host={myapp}.herokuapp.com request_id=9e9732fd-527d-4f28-b57b-1c817e74b711 fwd="ip" dyno=web.1 connect=2ms service=1ms status=404 bytes=118 protocol=https

CodePudding user response:

As per the comment above, Swagger was set only to development mode.

if (app.Environment.IsDevelopment())
    {
        app.UseSwagger();
        app.UseSwaggerUI();
    }

For the other routes, turns out I forgot to whitelist the IP address for in Mongo Atlas.

  • Related