Apollo 服务器在生产中隐藏 graphql ui

问题描述 投票:0回答:3

我一直在寻找对此的解释。这个问题有点“基本”,所以我希望尽快找到解决方案,但我没有。

我想在生产服务器中隐藏图形用户界面,这样任何人都看不到我的查询,但我不能。我可以轻松地弄清楚如何在本地和生产中使用不同的环境变量。我在文档中搜索但找不到方法。

提前致谢!

node.js graphql apollo-server
3个回答
2
投票

要禁用 UI,您可以使用

playground: false

进行配置

https://www.apollographql.com/docs/apollo-server/testing/graphql-playground/

const server = new ApolloServer({
  schema, 
  introspection: false,
  playground: false,
});

1
投票

也许您没有设置 NODE_ENV=生产。

在开发过程中,Apollo Server 在与 GraphQL 服务器本身相同的 URL 上启用 GraphQL Playground(例如 http://localhost:4000/graphql),并自动向 Web 浏览器提供 GUI。当 NODE_ENV 设置为生产时,GraphQL Playground(以及内省)将被禁用,作为生产最佳实践。


0
投票

使用 Apollo Server 4 的任何人 - 需要应用以下插件:ApolloServerPluginLandingPageDisabled() - 因为游乐场已从配置中删除。

© www.soinside.com 2019 - 2024. All rights reserved.