GraphQL + BananaCakePop在Docker容器中无法工作。

huangapple go评论83阅读模式
英文:

GraphQL + BananaCakePop won't work in a Docker container

问题

我正在创建一个使用GraphQL ASP.NET API和Hot Chocolate / BananaCakePop进行基于Web的查询的概念验证。目前,这只是一个最基本的API,只有一个查询点。我在VS中本地运行应用程序没有问题,但是当我尝试将其Docker化时遇到了问题。虽然我可以使用Postman在5148端口查询API,但是当我尝试使用Web浏览器访问时,控制台会显示404错误。

我的Dockerfile如下所示:

#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=http://*:5148/;http://*:7057/"]

我的错误如下所示:

2023-08-09 10:19:47 2023-08-09 09:19:47.598 [INF] [AUTH] [] Now listening on: http://[::]:5148
2023-08-09 10:19:47 2023-08-09 09:19:47.610 [INF] [AUTH] [] Now listening on: http://[::]: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 http://localhost:5148/ - -
2023-08-09 10:20:39 2023-08-09 09:20:39.175 [INF] [AUTH] [] Request finished HTTP/1.1 GET http://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 http://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 http://localhost:5148/graphql application/json 107 - 200 - application/graphql-response+json;+charset=utf-8 887.1841ms

有任何想法我做错了什么吗?

英文:

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=http://*:5148/;http://*:7057/"]

My errors are as follows:

2023-08-09 10:19:47 2023-08-09 09:19:47.598 [INF] [AUTH] [] Now listening on: http://[::]:5148
2023-08-09 10:19:47 2023-08-09 09:19:47.610 [INF] [AUTH] [] Now listening on: http://[::]: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 http://localhost:5148/ - -
2023-08-09 10:20:39 2023-08-09 09:20:39.175 [INF] [AUTH] [] Request finished HTTP/1.1 GET http://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 http://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 http://localhost:5148/graphql application/json 107 - 200 - application/graphql-response+json;+charset=utf-8 887.1841ms

Any ideas where I'm going wrong?

答案1

得分: 1

看起来你得到的404错误是因为你正在访问服务器的根目录(/),而在Postman中你正在访问图形路由(/graphql)。

默认情况下,图形不会为根URL添加任何映射,所以404错误是合理的。请再次尝试在URL中加上graphql,你应该会看到BCP弹出,就像你期望的那样。

英文:

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.

huangapple
  • 本文由 发表于 2023年8月9日 17:30:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76866371.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定