From 4d89db0b9832328e45801cb63ef4bfe9f77aca7a Mon Sep 17 00:00:00 2001 From: Yannis Barlas <yannisbarlas@gmail.com> Date: Mon, 26 Oct 2020 15:00:39 +0200 Subject: [PATCH] feat(server): add ability to disable server --- README.md | 18 ++++++++++++++++++ src/app.js | 16 ++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 537cc20..716a91e 100644 --- a/README.md +++ b/README.md @@ -155,6 +155,24 @@ cron.schedule('* * * * * *', () => { The library that enables this is `node-cron`. Be sure to check its [documentation](https://github.com/node-cron/node-cron#node-cron) for further details. +### Disable GraphQL + +There are cases where you might not want a graphql server at all. eg. If you are building a sevice with a single REST api endpoint with coko server. + +To disable graphql on the server, change the following value in your config: + +```js +// config/default.js + +module.exports = { + 'pubsweet-server': { + useGraphQLServer: false, + }, +} +``` + +_Note that this is `true` by default as using GraphQL will be the most common use case._ + ### CORS support for the client If you run your client on a different host/port than the server, you might run into issues where cross-origin requests are rejected. If that happens, make sure the following entries exist in your config. The server should take care of it once these are defined. diff --git a/src/app.js b/src/app.js index 2481b23..187d726 100644 --- a/src/app.js +++ b/src/app.js @@ -86,8 +86,20 @@ const configureApp = app => { app.use('/api', api) // REST API - const gqlApi = require('./graphqlApi') - gqlApi(app) // GraphQL API + let useGraphQLServer = true + if ( + config.has('pubsweet-server.useGraphQLServer') && + config.get('pubsweet-server.useGraphQLServer') === false + ) { + useGraphQLServer = false + } + + logger.warn('useGraphQLServer', useGraphQLServer) + + if (useGraphQLServer) { + const gqlApi = require('./graphqlApi') + gqlApi(app) // GraphQL API + } app.use('/', index) // Serve the index page for front end -- GitLab