4

我正在设置要使用的开发系统https,Chrome 抱怨我的 websocket 无法安全启动:

VM4965:161 混合内容:“ https://mywebsite.io/ ”页面已通过 HTTPS 加载,但尝试连接到不安全的 WebSocket 端点“ws://mywebsite.io:4000/subscriptions”。此请求已被阻止;此端点必须在 WSS 上可用。

这是我当前的 WS 服务器端设置,基于 Apollo 文档:

const localHostString = 'mywebsite.io'; 
const pubsub = new PubSub();

// additional context you use for your resolvers, if any
const context = {connectors: connectors};

//SET UP APOLLO QUERY / MUTATIONS / PUBSUB
//start a graphql server with Express handling a possible Meteor current user
createApolloServer({
    schema,
    context
});

const METEOR_PORT = 3000;
const GRAPHQL_PORT = 4000;
const server = express();

server.use('*', cors({ origin: `https://${localHostString}:${METEOR_PORT}` }));

server.use('/graphql', bodyParser.json(), graphqlExpress({
    schema,
    context
}));

server.use('/graphiql', graphiqlExpress({
    endpointURL: '/graphql',
    subscriptionsEndpoint: `ws://${localHostString}:${GRAPHQL_PORT}/subscriptions`
}));

// Wrap the Express server
const ws = createServer(server);
ws.listen(GRAPHQL_PORT, () => {
    console.log(`GraphQL Server is now running on http://${localHostString}:${GRAPHQL_PORT}`);
    console.log(`GraphiQL available at http://${localHostString}:${GRAPHQL_PORT}/graphiql`);
    // Set up the WebSocket for handling GraphQL subscriptions
    new SubscriptionServer({
        execute,
        subscribe,
        schema
    }, {
        server: ws,
        path: '/subscriptions',
    });
});

如何更新它以使用 WSS 而不是 WS websockets?

提前感谢所有人提供的任何信息。

4

1 回答 1

7

看起来你在做

subscriptionsEndpoint: `ws://${localHostString}:${GRAPHQL_PORT}/subscriptions

也许相反,ws改为wss. IE:

subscriptionsEndpoint: `wss://${localHostString}:${GRAPHQL_PORT}/subscriptions
于 2018-07-19T01:42:59.703 回答