Skip to content
Browse files

Put the basic skeleton in place

  • Loading branch information...
1 parent a021073 commit 107ddefa460e3db378f860fc1f53ff3651f94271 Mark Cahill committed
Showing with 78 additions and 0 deletions.
  1. +18 −0 listeners/couchdb.js
  2. +26 −0 server.js
  3. +34 −0 telemetry.js
View
18 listeners/couchdb.js
@@ -0,0 +1,18 @@
+var Backbone = require('backbone');
+
+var Event = exports.event = Backbone.Model.extend({
+ url: function() {
+ return 'http://' + this.get('username') + ':' + this.get('password') +
+ '@' + this.get('host') + ':' + this.get('port') +
+ '/' + this.get('database');
+ }
+});
+
+exports.events = Backbone.Collection.extend({
+ model: Event,
+ url: function() {
+ return 'http://' + this.get('username') + ':' + this.get('password') +
+ '@' + this.get('host') + ':' + this.get('port') +
+ '/' + this.get('database') + '/_all_docs';
+ }
+});
View
26 server.js
@@ -0,0 +1,26 @@
+// Import libraries
+var express = require('express');
+var Backbone = require('backbone');
+var yaml = require('yaml');
+var fs = require('fs');
+var headers = {
+ accept:'application/json',
+ 'content-type':'application/json'
+};
+
+// Load listeners
+var listeners = {};
+var listener_files = fs.readdirSync(__dirname + "/listeners");
+for (var i = 0; i < listener_files.length; i++) {
+ var listener = listener_files[i].replace('.js', '');
+ window[listener] = require(listener);
+}
+
+//Load configuration and inputs
+var telemetry = new require(__dirname + '/telemetry')(config);
+
+// Create the telemetry server and assign inputs
+var app = express.createServer();
+app.post('/input/:input', telemetry.new_event);
+
+// Start the telemetry server
View
34 telemetry.js
@@ -0,0 +1,34 @@
+var Backbone = require('backbone');
+
+exports = module.exports = Backbone.Model.extend({
+ /**
+ * The inputs that are listening on this server
+ */
+ inputs: {},
+
+ /**
+ * Read in configuration and set up inputs
+ * @param config
+ */
+ initialize: function(config) {
+ // Load inputs
+ },
+
+ /**
+ * Post a new event to the server
+ * @param req
+ * @param res
+ * @param next
+ */
+ new_event: function(req, res, next) {
+ var input = req.params.input;
+ if (! input in this.inputs) {
+ // Bad input, send 404
+ res.end('', 404);
+ }
+
+ // Send success
+ res.end('', 200);
+ this.inputs[input].trigger('event:new', req.body);
+ }
+});

0 comments on commit 107ddef

Please sign in to comment.
Something went wrong with that request. Please try again.