在生产中禁用graphiql [英] disable graphiql on production

查看:120
本文介绍了在生产中禁用graphiql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在生产环境中禁用graphiql,但仍能在开发时访问它?

How can I disable graphiql on production but still able to access it on development?

借助express-graphql,我们可以做类似的事情

With express-graphql we can do something like

app.use('/graphql', graphqlHTTP({
  schema: MySessionAwareGraphQLSchema,
  graphiql: process.env.NODE_ENV === 'development',
}));

对于apollo服务器,我的设置是

With apollo server, my setup is

import {graphqlExpress, graphiqlExpress} from 'graphql-server-express'

const app = new Express()

app
  .all('/graphql', bodyParser.json())
  .all('/graphql', graphqlExpress({
      schema
  )
  .all('/graphiql', graphiqlExpress({
      endpointURL: 'http://localhost/graphql'
    })
  )

我找不到传递给NODE_ENV来启用/禁用graphiql的方法.

and I can't find a way to pass to NODE_ENV to enable/disable graphiql.

推荐答案

您的意思是仅在开发中启用graphiql并在生产中禁用它.如果是这样,只需排除/graphiql处理程序

Do you mean to enable graphiql on development only and disable it on production. If so just exclude the /graphiql handler

if (process.env.NODE_ENV === 'development') {
  app.all(
    '/graphiql',
    graphiqlExpress({
      endpointURL: '/graphql',
    }),
  );
}

这篇关于在生产中禁用graphiql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆