【问题标题】:Node GCM with proxy - port 443 disabled带代理的节点 GCM - 端口 443 已禁用
【发布时间】:2016-05-27 11:33:10
【问题描述】:

我正在使用插件https://www.npmjs.com/package/node-gcm

在没有设置任何代理的情况下启用端口 443 可以正常工作。但我需要它在禁用 443 的 RHEL 环境中工作。

代理后面的节点 GCM 插件。下面是代码

var message = new gcm.Message();

            // ... or some given values 
            var message = new gcm.Message({
              collapseKey: 'demo',
              priority: 'high',
              contentAvailable: true,
              delayWhileIdle: true,
              //timeToLive: 10000,
              restrictedPackageName: '',
              dryRun: false
            });


            var notification_title = config_file.gcm.gcm_title ? config_file.gcm.gcm_title.replace(/\\'/g,"'") : '';
            var message_content = config_file.gcm.gcm_content ? config_file.gcm.gcm_content.replace(/\\'/g,"'") : '';
            // as object 
            message.addNotification({
                title: notification_title,
                body: '',
                icon: 'notification',
                tag: false,
                sound: true
            });



            // Set up the sender with you API key 
            var requestOptions = {
                proxy: 'http://aws-public-ip:8000',
                timeout: 1000
                // strictSSL: false,
                // method: 'POST'
            };
            var sender = new gcm.Sender(config_file.gcm.gcm_api, requestOptions);

            // Add the registration tokens of the devices you want to send to 
            var tokens = [];
            for(var t = 0; t < token.length; t++)
            {
                tokens.push(token[t].gcm_token);
            }

            // Max devices per request    
            var batchLimit = 1000;

            // Batches will be added to this array
            var tokenBatches = [];

            // Traverse tokens and split them up into batches of 1,000 devices each  
            for ( var start = 0; start < tokens.length; start += batchLimit )
            {
                // Get next 1,000 tokens
                var slicedTokens = tokens.splice(start, start + batchLimit);

                // Add to batches array
                tokenBatches.push(slicedTokens);
            }
            // You can now send a push to each batch of devices, in parallel, using the caolan/async library
            async.each( tokenBatches, function( batch, callback )
            {
                // Assuming you already set up the sender and message
                sender.send(message, { registrationTokens: batch }, function(err, response) {  

                    // Push failed?
                    if (err)
                    {
                        // Stops executing other batches
                        console.log('ds');
                        console.log(err);
                    }
                    else {
                        console.log('ts');
                        console.log(response);
                    }
                    // Done with batch
                    callback();
                });
            },
            function( err )
            {
                // Log the error to console
                if ( err )
                {
                    console.log(err);
                }
            });

我还启用了 8000 的传出端口。下面还有在 aws 和 npm 中启用代理的命令

export HTTP_PROXY="http://aws-public-ip:8000"
export HTTPS_PROXY="http://aws-public-ip:8000"
export NO_PROXY="169.254.169.254"
export http_proxy="http://aws-public-ip:8000"
export https_proxy="http://aws-public-ip:8000"
export no_proxy="169.254.169.254"
npm config set proxy http://aws-public-ip:8000
npm config set https-proxy http://aws-public-ip:8000
npm config set strict-ssl false
npm config set registry http://registry.npmjs.org
sudo npm config set proxy http://aws-public-ip:8000 -g

我收到错误{ [Error: tunneling socket could not be established, cause=socket hang up] code: 'ECONNRESET' }

TL DR:我不确定我是否使用上述命令在 aws 中正确设置了代理。另外,我不确定插件是否可以在禁用 443 端口的情况下工作。

【问题讨论】:

    标签: android node.js proxy google-cloud-messaging xmpp


    【解决方案1】:

    我的错误。代理地址应该是正确的 ip,它接受代理并连接到 443 端口。

    我使用与代理相同的 aws ip 不知道代理到底是什么。

    我使用 ubuntu 操作系统在 aws 中创建了另一个实例并安装了微型代理。打开所需的端口并在我的应用程序中提供新的实例 ip 作为代理,它可以工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-31
      • 1970-01-01
      • 2017-09-07
      • 1970-01-01
      • 2020-07-11
      • 1970-01-01
      • 1970-01-01
      • 2019-09-01
      相关资源
      最近更新 更多