Meteor/Apollo:HTTPS 和 WS 的 SSL 访问? [英] Meteor/Apollo: SSL Access for HTTPS and WS?

查看:26
本文介绍了Meteor/Apollo:HTTPS 和 WS 的 SSL 访问?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让 SSL 在 Meteor 中为 https 和 websockets 工作.我收到此错误:

(STDERR) 错误:听 EACCES 0.0.0.0:443

这是我的设置.

对于 SSL 访问,我安装了 nourharidy/meteor-ssl.我可以使用人们认为有用的任何类似的包或方法!

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

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

这是我的其余设置:

我的 ROOT_URL 环境变量是:

https://10.0.1.10:443//我正在使用我的 Mac 的 IP 地址,以便另一台 Mac 可以访问它

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

//设置APOLLO QU​​ERY/MUTATIONS/PUBSUBconst USING_HTTPS = true;const httpProtocol = USING_HTTPS ?"https": "http";const localHostString = '10.0.1.10'//我正在使用我的 Mac 的 IP 地址,以便另一台 Mac 可以访问它const METEOR_PORT = 443;const GRAPHQL_SUBSCRIPTION_PORT = 4000;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({模式}));server.use('/graphiql', graphiqlExpress({端点网址:'/graphql',订阅端点:订阅端点}));//我们包装了 express 服务器,以便我们可以附加 WebSocket 进行订阅const ws = createServer(server);ws.listen(GRAPHQL_SUBSCRIPTION_PORT, () => {console.log(`GraphQL Server 现在运行在 ${httpProtocol}://${localHostString}:${GRAPHQL_SUBSCRIPTION_PORT}`);//设置 WebSocket 来处理 GraphQL 订阅新订阅服务器({执行,订阅,模式}, {服务器:ws,路径:'/订阅',});});

我错过了什么?

非常感谢大家提供任何信息!

解决方案

解决了!事实证明我的服务器设置很好.

服务器端我像这样构建 WSS url:

var websocketUri = Meteor.absoluteUrl('subscriptions').replace(/http/, 'ws').replace('3100', '3200');

absoluteUrl 的 Meteor 文档说:

<块引用>

服务器从 ROOT_URL 环境变量中读取数据以确定它在何处运行.

在 Webstorm 中,我将 ROOT_URL 设置为 https://10.0.nn.nn:3100.但由于某种原因,absoluteUrl 返回了 http://10.0.nn.nn:3000.IE.它有错误的端口.

更正端口后 - 它可以工作了!

更新: 几天前我发帖时我以为我已经解决了,但我仍然遗漏了一些东西.

我现在使用 ngrok 为我的开发系统提供 SSL,以便与 HTTPS 和 WSS 配合使用.>

这里有一些细节.

  • 我在 localhost:3000 上运行 Meteor.
  • 我将http://localhost:3000"的值分配给 ROOT_URL 环境变量.
  • 我同时运行两个 ngrok 连接,一个用于 HTTPS,一个用于 WSS:

<代码>./ngrok http 3000./ngrok http 3200

  • 这给了我两个 ngrok 网址,例如:
<块引用>

转发 https://9b785bd3.ngrok.io -> localhost:3000
转发 https://ec3d8027.ngrok.io -> localhost:3200

我通过 ngrok url 访问我的应用程序,例如:

<块引用>

https://9b785bd3.ngrok.io

我基于 ngrok 地址构建了我的 HTTPS 链接和 WSS 链接.例如:

const wssEndpoint = 'wss://ec3d8027.ngrok.io/subscriptions';

我希望这对其他人有帮助.

I’m trying to get SSL working in Meteor for https and websockets. I’m getting this error:

(STDERR) Error: listen EACCES 0.0.0.0:443

Here's my setup.

For SSL access I have installed nourharidy/meteor-ssl. I can use any comparable package or approach that people have found useful!

As required by nourharidy/meteor-ssl, in server/main.js I have:

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

Here's the rest of my setup:

My ROOT_URL environment variable is:

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

In imports/startup/server/index.js I have:

//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 = 443;
const GRAPHQL_SUBSCRIPTION_PORT = 4000;
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',
    });
});

What am I missing?

Thanks very much in advance to all for any info!

解决方案

Solved it! It turns out my server setup was fine.

Server-side I was building the WSS url like so:

var websocketUri = Meteor.absoluteUrl('subscriptions').replace(/http/, 'ws').replace('3100', '3200');

The Meteor docs for absoluteUrl say:

The server reads from the ROOT_URL environment variable to determine where it is running.

In Webstorm I have ROOT_URL set to https://10.0.nn.nn:3100. But for some reason absoluteUrl was returning http://10.0.nn.nn:3000. I.e. it had the wrong port.

After correcting the port-- it’s working!

UPDATE: I thought I had it solved when I posted a few days ago, but I was still missing something.

I'm now using ngrok to provide SSL to my dev system for use with HTTPS and WSS.

Here are a few details.

  • I run Meteor on localhost:3000.
  • I assign the value of "http://localhost:3000" to the ROOT_URL environment variable.
  • I run two simultaneous ngrok connections, one for HTTPS and one for WSS:

./ngrok http 3000 ./ngrok http 3200

  • This gives me two ngrok urls, for example:

Forwarding https://9b785bd3.ngrok.io -> localhost:3000
Forwarding https://ec3d8027.ngrok.io -> localhost:3200

I access my app via the ngrok url, for example:

https://9b785bd3.ngrok.io

I build my HTTPS links and WSS links based on the ngrok addresses. For example:

const wssEndpoint = 'wss://ec3d8027.ngrok.io/subscriptions';

I hope this is helpful to others looking into this.

这篇关于Meteor/Apollo:HTTPS 和 WS 的 SSL 访问?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆