Last active
August 29, 2015 14:01
-
-
Save AndyStewart/ff21cae5aab27f2437c2 to your computer and use it in GitHub Desktop.
Reading from eventStore using node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var request = require('request'); | |
var async = require('async'); | |
function eventStore() { | |
function createEvent(event, body) { | |
return { | |
data: body, | |
type: event.summary | |
}; | |
} | |
function getEvent(event, callback) { | |
var requestOptions = optionBuilder(event.id); | |
request(requestOptions, function(error, response, body) { | |
return callback(error, createEvent(event, body)); | |
}); | |
} | |
function getEventsInStream(streamName, callback) { | |
var requestOptions = optionBuilder("http://localhost:2113/streams/" + streamName); | |
request(requestOptions, function(error, response, body) { | |
async.map(body.entries, getEvent, callback); | |
}); | |
} | |
return { | |
getEventsInStream: getEventsInStream | |
}; | |
} | |
var optionBuilder = function(url) { | |
var host = url; | |
var options = { | |
json: true, | |
'auth': { | |
'user': 'admin', | |
'pass': 'changeit', | |
'sendImmediately': false | |
}, | |
url: url, | |
}; | |
return options; | |
}; | |
module.exports = eventStore(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var eventStore = require('./eventStore'); | |
exports.index = function(req, res){ | |
var id = req.params.id; | |
eventStore.getEventsInStream("esubs-Guest-form-" + req.params.id, function(err, events) { | |
res.send({history: events }); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment