如何为WebSocketLink uri设置代理

时间:2019-09-13 03:27:18

标签: reactjs heroku websocket react-apollo apollo-client

我想将我的React应用程序部署到Heroku,但是我不知道如何在setupProxy.js中为Web套接字设置代理,或者如果我不设置代理,它是否可以工作?

我尝试过

const wsLink = new WebSocketLink({
  uri: "/subscriptions",
  options: {
    reconnect: true,
    connectionParams: {
      authToken: localStorage.getItem(AUTH_TOKEN)
    }
  }
});

in index.js and 

  app.use(
      "subscriptions",
      proxy({
        target: "ws://localhost:4000",
        changeOrigin: true,
        ws: true
      })
    );
in setupProxy.js but it doesn't work


const wsLink = new WebSocketLink({
  uri: "ws://localhost:4000/subscriptions",
  options: {
    reconnect: true,
    connectionParams: {
      authToken: localStorage.getItem(AUTH_TOKEN)
    }
  }
});

0 个答案:

没有答案