Node.js 为什么我的GraphQL订阅在本地服务器上工作,但在live server上部署时不工作

Node.js 为什么我的GraphQL订阅在本地服务器上工作,但在live server上部署时不工作,node.js,express,heroku,graphql,express-graphql,Node.js,Express,Heroku,Graphql,Express Graphql,我正在构建一个GraphQL服务器,其中包含订阅。一旦我在本地机器上部署了服务器,并在Playplace中检查订阅,它就会工作,也就是说,它会侦听事件,我会获取新添加的数据。这意味着订阅实现是正确的,并且没有任何问题。当我在本地(即本地主机)上运行时,订阅工作正常,但当我在live(Heroku)上部署服务器时,当我在游乐场中收听订阅时,会出现以下错误: { "error": "Could not connect to websocket endpoint ws

我正在构建一个GraphQL服务器,其中包含订阅。一旦我在本地机器上部署了服务器,并在Playplace中检查订阅,它就会工作,也就是说,它会侦听事件,我会获取新添加的数据。这意味着订阅实现是正确的,并且没有任何问题。当我在本地(即本地主机)上运行时,订阅工作正常,但当我在live(Heroku)上部署服务器时,当我在
游乐场
中收听订阅时,会出现以下错误:

{
  "error": "Could not connect to websocket endpoint wss://foodesk.herokuapp.com/graphql. Please check if the endpoint url is correct."
}
只是为了获得更多信息,我的查询和变异也在live server上工作,只是订阅不起作用

这是我的代码:

/**
 * third party libraries
 */
const bodyParser = require('body-parser');
const express = require('express');
const { ApolloServer } = require('apollo-server-express');
const helmet = require('helmet');
const http = require('http');
const mapRoutes = require('express-routes-mapper');
const mkdirp = require('mkdirp');
const shortid = require('shortid');
/**
 * server configuration
 */
const config = require('../config/');
const auth = require('./policies/auth.policy');
const dbService = require('./services/db.service');
const { schema } = require('./graphql');

// environment: development, testing, production
const environment = process.env.NODE_ENV;


const graphQLServer = new ApolloServer({
  schema,
  uploads: false
});

/**
 * express application
 */
const api = express();
const server = http.createServer(api);

graphQLServer.installSubscriptionHandlers(server)

const mappedRoutes = mapRoutes(config.publicRoutes, 'api/controllers/');
const DB = dbService(environment, config.migrate).start();

// allow cross origin requests
// configure to allow only requests from certain origins
api.use(function (req, res, next) {

  // Website you wish to allow to connect
  res.setHeader('Access-Control-Allow-Origin', '*');

  // Request methods you wish to allow
  res.setHeader('Access-Control-Allow-Methods', '*');

  // Request headers you wish to allow
  res.setHeader('Access-Control-Allow-Headers', '*');

  // Pass to next layer of middleware
  next();
});

// secure express app
api.use(helmet({
  dnsPrefetchControl: false,
  frameguard: false,
  ieNoOpen: false,
}));

// parsing the request bodys
api.use(bodyParser.urlencoded({ extended: false }));
api.use(bodyParser.json());

// public REST API
api.use('/rest', mappedRoutes);

// private GraphQL API
api.post('/graphql', (req, res, next) => auth(req, res, next));

graphQLServer.applyMiddleware({
  app: api,
  cors: {
    origin: true,
    credentials: true,
    methods: ['POST'],
    allowedHeaders: [
      'X-Requested-With',
      'X-HTTP-Method-Override',
      'Content-Type',
      'Accept',
      'Authorization',
      'Access-Control-Allow-Origin',
    ],
  },
  playground: {
    settings: {
      'editor.theme': 'light',
    },
  },
});

server.listen(config.port, () => {
  if (environment !== 'production'
    && environment !== 'development'
    && environment !== 'testing'
  ) {
    console.error(`NODE_ENV is set to ${environment}, but only production and development are valid.`);
    process.exit(1);
  }
  return DB;
});


你解决这个问题了吗?没有,先生,我不能。