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

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

问题描述

我试图让SSL在Meteor中为https和websockets工作。我得到这个错误:

 (STDERR)错误:listen EACCES 0.0.0.0:443 

这是我的设置。



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



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



$ p $ 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查询/突变/ PUBSUB 
const 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({
schema
}));
server.use('/ graphiql',graphiqlExpress({
endpointURL:'/ graphql',
subscriptionsEndpoint:subscriptionsEndpoint
}));
//我们包装express服务器,以便我们可以附加WebSocket进行订阅
const ws = createServer(server);
ws.listen(GRAPHQL_SUBSCRIPTION_PORT,()=> {
console.log(``GraphQL Server现在运行在$ {httpProtocol}:// $ {localHostString}:$ {GRAPHQL_SUBSCRIPTION_PORT}`);

//设置WebSocket来处理GraphQL订阅
新SubscriptionServer({
execute,
subscribe,
schema
},{
服务器:ws,
路径:'/ subscriptions',
});
});

我错过了什么?



谢谢非常提前,所有的任何信息!

解决方案

解决了它!事实证明,我的服务器设置没问题。



服务器端我正在构建WSS url,如下所示:



<$ ('http:','ws')。replace('3100','3200'); p $ p> var websocketUri = Meteor.absoluteUrl('subscriptions')。

Meteor文件用于 absoluteUrl 说:


服务器从ROOT_URL读取环境变量来确定它在哪里运行。

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



更正端口后,它正在工作!


$ b

更新: 我以前在几天前发布时已经解决了这个问题,但我仍然失去了一些东西。



我现在使用 ngrok 提供SSL我的开发系统与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 =nofollow noreferrer> 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天全站免登陆