英文:
GraphQL server connection refused in production server
问题
我有一个正在本地开发的Angular/GraphQL/MySQL应用程序,现在我想将其投入生产环境。
我已经在DigitalOcean上创建了一个Droplet,并注册了一个GoDaddy域名。我在服务器上安装了Nginx并创建了一个服务器块,然后将我的客户端文件夹传输到了服务器上。
当我访问URL时,我可以看到我的客户端正在运行,但当我尝试与GraphQL服务器互动时,出现以下错误:
> POST http://localhost:9000/graphql net::ERR_CONNECTION_REFUSED
在我的服务器上,Express服务器正在运行,如果我再次运行/server/index.js
,则会显示以下错误:
> Error: listen EADDRINUSE: address already in use :::9000
我已经按照这个指南的步骤进行了设置,但server
块中的更改导致无法提供客户端的URL,因此我认为这是错误的方法。
英文:
I have a Angular/GraphQL/MySQL application that I've been developing locally and now I want to put it into production.
I've set up a DigitalOcean droplet and I've registered a GoDaddy domain. I've set up Nginx on the server and created a server block and transferred my client folder to the server and.
When I navigate to the URL I do get the see my client running, but when I want to interact with the GraphQL server I get a:
> POST http://localhost:9000/graphql net::ERR_CONNECTION_REFUSED
On my server I do have the express server running, the following error shows if I run my /server/index.js
again:
> Error: listen EADDRINUSE: address already in use :::9000
I've followed this guide but the changes in the server
block stopped the url from serving the client, so I think that's the wrong approach.
答案1
得分: 0
问题出在我的 graphql.module.ts
http 配置指向了我的 localhost
。但我已经通过更新 URI 来解决了这个问题:
export function createApollo(httpLink: HttpLink): ApolloClientOptions<unknown> {
const http = httpLink.create({
uri: 'http://example.com:9000/graphql',
});
我认为你需要更新 Nginx 配置以包括 GraphQL 端点:
location /graphql {
proxy_pass http://example.com:9000/graphql;
}
英文:
Issue here was that my graphql.module.ts
http config pointed to my localhost
. But I've resolved the issue by updating the uri:
export function createApollo(httpLink: HttpLink): ApolloClientOptions<unknown> {
const http = httpLink.create({
uri: 'http://example.com:9000/graphql',
});
I do believe you need to update the nginx config to include the graphql endpoint:
location /graphql {
proxy_pass http://example.com:9000/graphql;
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论