Skip to content

Instantly share code, notes, and snippets.

@theojulienne
Forked from wolfeidau/httpstest3.js
Created November 3, 2013 03:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theojulienne/7286382 to your computer and use it in GitHub Desktop.
Save theojulienne/7286382 to your computer and use it in GitHub Desktop.
'use strict';
var url = require('url');
var creds = require('./creds.js');
var https = require('https');
var scheme = 'https';
var hostname = 'api.tempo-db.com';
var baseUrl = scheme + '://' + hostname;
var auth = 'Basic ' + new Buffer(creds.key + ':' + creds.secret).toString('base64');
var seriesKey = '1_D90343085872CA9C_687_0_2000';
var myAgent = new https.Agent({keepAlive: true}); // undocumented magic
function uploadEntry(cb){
var data = [];
data.push({t: new Date(), v: Math.random() * 50});
var body = JSON.stringify(data);
var headers = {
Authorization: auth,
'Content-Type': 'application/json',
'Content-Length': body.length,
'Connection': 'keep-alive'
};
var opts = {
host: hostname,
port: 443,
path: '/v1/series/key/' + seriesKey + '/data/',
method: 'POST',
agent: myAgent,
headers: headers
};
// console.log('sending', data[0]);
var req = https.request(opts,cb);
req.on('error', function(e) {
console.err('error', e);
});
req.write(body);
req.end();
};
function callback(result){
console.log('statusCode', result.statusCode);
result.on('data', function (chunk) {}); // consume so we don't leak sockets
}
setInterval(uploadEntry.bind(null, callback), 1000);
setInterval(gc, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment