Skip to content

Instantly share code, notes, and snippets.

@alancasagrande
Created September 4, 2014 18:15
Show Gist options
  • Save alancasagrande/e7e256d8762abea538af to your computer and use it in GitHub Desktop.
Save alancasagrande/e7e256d8762abea538af to your computer and use it in GitHub Desktop.
Simple client to test the multi-tenant app
var request = require('superagent');
var _ = require('underscore');
function firePost (tenant) {
var name = 'Post from tenant ' + tenant;
request
.post('http://localhost:3000/posts?tenant=t' + tenant)
.send({ name: name })
.set('Content-Type', 'application/json')
.end(function (err, res) {
if (err) { console.error(err); }
else { console.log(tenant, name, 'created'); }
firePost(_.random(0, 39));
});
}
function fireGet (tenant) {
request
.get('http://localhost:3000/posts?tenant=t' + tenant)
.end(function (err, res) {
if (err) { console.error(err); }
else { console.log(tenant, 'count', res.body.count); }
fireGet(_.random(0, 39));
});
}
fireGet(_.random(0, 39));
firePost(_.random(0, 39));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment