我正在使用插件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端口的情况下使用。
答案 0 :(得分:0)
我的错误。代理地址应该是正确的ip,它接受代理并且连接到443端口打开。
我使用相同的aws作为代理,而不知道代理是什么。
我用ubuntu操作系统在aws中创建了另一个实例并安装了小代理。打开所需的端口并在我的应用程序中提供新的实例ip作为代理,它可以工作。