Meteor / Apollo:SSL强制HTTPS与WSS一样进入同一端口?

时间:2017-09-25 23:28:05

标签: node.js meteor websocket graphql apollo

我试图在我的本地开发环境中使用HTTPS和WSS(用于Apollo订阅)。即使我将它们放在两个不同的端口上,似乎有些东西强制或将WSS调用重定向到HTTPS端口。

这是我目前的代码。对于SSL访问,我安装了Meteor包nourharidy/meteor-ssl。我可以使用人们认为有用的任何类似的包或方法!

根据nourharidy/meteor-ssl的要求,在server / main.js中我有:

SSL('/path/to/private/server.key','/path/to/private/server.crt', 3100);

我的ROOT_URL环境变量是:

https://10.0.1.10:3100 //I’m using my Mac’s ip address so that another Mac can access it

在imports / startup / server / index.js中我有:

//SET UP APOLLO QUERY / MUTATIONS / PUBSUB
const USING_HTTPS = true;
const httpProtocol =  USING_HTTPS ? "https" : "http"; 
const localHostString = '10.0.1.10' //I’m using my Mac’s ip address so that another Mac can access it

const METEOR_PORT = 3100;
const GRAPHQL_SUBSCRIPTION_PORT = 3200;
const subscriptionsEndpoint = `wss://${localHostString}:${GRAPHQL_SUBSCRIPTION_PORT}/subscriptions`;

const server = express();
server.use('*', cors({ origin: `${httpProtocol}://${localHostString}:${GRAPHQL_SUBSCRIPTION_PORT}` }));
server.use('/graphql', bodyParser.json(), graphqlExpress({
    schema
}));
server.use('/graphiql', graphiqlExpress({
    endpointURL: '/graphql',
    subscriptionsEndpoint: subscriptionsEndpoint
}));
// We wrap the express server so that we can attach the WebSocket for subscriptions
const ws = createServer(server);
ws.listen(GRAPHQL_SUBSCRIPTION_PORT, () => {
    console.log(`GraphQL Server is now running on ${httpProtocol}://${localHostString}:${GRAPHQL_SUBSCRIPTION_PORT}`);

    // Set up the WebSocket for handling GraphQL subscriptions
    new SubscriptionServer({
        execute,
        subscribe,
        schema
    }, {
        server: ws,
        path: '/subscriptions',
    });
});

而不是https://10.0.1.10:3200/graphiql它应该在哪里,graphIql位于https://10.0.1.10:3100/graphiql!换句话说,graphIql在https://10.0.1.10:3100/graphiql上加载就好了,但是如果你转到https://10.0.1.10:3200/graphiql,就会看到10.0.1.10 unexpectedly closed the connection

如果我将HTTPS和WSS放在同一个端口上,例如3100,我收到listen EADDRINUSE :::3100错误。

在Meteor / Apollo中获得HTTPS和WSS的服务器端设置是什么?

提前致谢所有信息。

0 个答案:

没有答案