1

我创建了几个选项卡来显示 GraphQL 操场上的示例查询。在添加选项卡时,我还需要设置端点/服务器 URL,查询将在其中实际执行。下面是我的代码:

const startServer = async () => {
  const server = new ApolloServer({
    schema,
    introspection: true,
  playground: {
    tabs: [{
        name: 'data analysis',
        endpoint: '', // want to set the server url here
        query: '{ ... }'
      }
    ]
  }
});

  server.listen(PORT);
};

我可以为生产设置硬编码 URL,但我不想这样做。我想根据环境(localhost,dev,production)动态设置它。我尝试的一种方法是在服务器开始侦听端口后获取 URL,但它始终是http://localhost:PORT,这是不正确的。知道如何动态获取生产服务器 URL 以在此处设置。我在Node.js. 任何帮助将不胜感激。

4

0 回答 0