小编jli*_*ann的帖子

Apollo Server 作为 Nuxt 服务器中间件

我已经设法在 Nuxtjs 中拥有一个 Express + Apollo 后端作为服务器中间件。一切工作正常(身份验证、缓存、数据源、查询、突变),但现在我试图让订阅(websockets)运行,这给我带来了困难。

我尝试了这个示例https://www.apollographql.com/docs/apollo-server/data/subscriptions/#subscriptions-with-additional-middleware但即使让 httpServer 监听也不起作用。

这是我通过 nuxt.config.js 需要的 API 文件'~/api/index'

module.exports = async () => {
  const app = require('express')()
  const server = await require("./apollo")() // apollo-server-express w/ typeDefs and resolvers

  // apply Apollo to Express
  server.applyMiddleware({ app });
  console.log(` ApolloServer ready at ${server.graphqlPath}`);

  const httpServer = http.createServer(app);
  server.installSubscriptionHandlers(httpServer);
  console.log(` ApolloSubscriptions ready at ${server.subscriptionsPath}`);

  return {
    path: '/api',
    handler: httpServer
  }
}
Run Code Online (Sandbox Code Playgroud)

现在我的游乐场给了我这个错误:"Could not connect to websocket endpoint ws://192.168.150.98:3000/api/graphql. Please …

subscription websocket express apollo nuxt.js

3
推荐指数
1
解决办法
2411
查看次数

标签 统计

apollo ×1

express ×1

nuxt.js ×1

subscription ×1

websocket ×1