在生产中禁用 graphiql [英] disable graphiql on production
本文介绍了在生产中禁用 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屋!
查看全文