I’m creating a proof of concept with a GraphQL ASP.NET API and Hot Chocolate / BananaCakePop for web-based querying by local developers. It is just the most basic API at present with a single query point. I have the app running fine locally in VS but am having problems when I try to Dockerize it. While I can query the API using Postman on port 5148 when I try to access it using the web browser it gives me a 404 error in the console.
My dockerfile is as follows:
#Pull a builder image
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env
WORKDIR /App
EXPOSE 7057
EXPOSE 5148
# Copy solution over (.dockerIgonore excludes bin, obj etc)
COPY . ./
# Restore nuget packages
RUN dotnet restore
# Build the solution
RUN dotnet build -c Release
# Build and publish the web api project
RUN dotnet publish -c Release -o ./out
# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /App
# Copy publish output to final container
COPY --from=build-env /App/out .
ENTRYPOINT ["dotnet", "My.Api.dll", "--urls=https://*:5148/;https://*:7057/"]
My errors are as follows:
2023-08-09 10:19:47 2023-08-09 09:19:47.598 [INF] [AUTH] [] Now listening on: https://[::]:5148
2023-08-09 10:19:47 2023-08-09 09:19:47.610 [INF] [AUTH] [] Now listening on: https://[::]:7057
2023-08-09 10:19:47 2023-08-09 09:19:47.613 [INF] [AUTH] [] Application started. Press Ctrl+C to shut down.
2023-08-09 10:19:47 2023-08-09 09:19:47.613 [INF] [AUTH] [] Hosting environment: Production
2023-08-09 10:19:47 2023-08-09 09:19:47.613 [INF] [AUTH] [] Content root path: /App/
2023-08-09 10:20:39 2023-08-09 09:20:39.151 [INF] [AUTH] [] Request starting HTTP/1.1 GET https://localhost:5148/ - -
2023-08-09 10:20:39 2023-08-09 09:20:39.175 [INF] [AUTH] [] Request finished HTTP/1.1 GET https://localhost:5148/ - - - 404 0 - 26.1855ms
2023-08-09 10:20:47 2023-08-09 09:20:47.166 [INF] [AUTH] [] Request starting HTTP/1.1 POST https://localhost:5148/graphql application/json 107
2023-08-09 10:20:47 2023-08-09 09:20:47.169 [INF] [AUTH] [] Executing endpoint 'Hot Chocolate GraphQL Pipeline'
2023-08-09 10:20:47 2023-08-09 09:20:47.576 [INF] [AUTH] [] [SolrContentQuery] graphQL query
2023-08-09 10:20:48 2023-08-09 09:20:48.051 [INF] [AUTH] [] Executed endpoint 'Hot Chocolate GraphQL Pipeline'
2023-08-09 10:20:48 2023-08-09 09:20:48.053 [INF] [AUTH] [] Request finished HTTP/1.1 POST https://localhost:5148/graphql application/json 107 - 200 - application/graphql-response+json;+charset=utf-8 887.1841ms
Any ideas where I’m going wrong?
1 Answer
It looks like the 404 you are getting is because you are navigating to the root of the server (/
), whereas on postman you are hitting the graph route (/graphql
).
By default graph doesn’t add any mappings for the root url so it makes sense that would 404, try again with graphql in the URL and you should see BCP popping up as you would expect.