Я использую плагин https://www.npmjs.com/package/node-gcmУзел GCM с прокси - порт 443 инвалидов
Он прекрасно работает с портом 443 включен без прокси настроен. Но мне нужно, чтобы он работал в среде RHEL с отключенным 443.
Узел 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 и НПМ
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.