minimal changes to get /pebble to do something as-is

With @brandonarbiter et al. :-)

* Also, this includes a change which allows mongo keys to be specified in the azure website.

curl -isv localhost:1337/pebble | json

* Adding handle: conn: 0x2108b90
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x2108b90) send_pipe: 1, recv_pipe: 0
* About to connect() to localhost port 1337 (#0)
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 1337 (#0)
> GET /pebble HTTP/1.1
> User-Agent: curl/7.32.0
> Host: localhost:1337
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Sun, 04 May 2014 19:57:44 GMT
< Connection: keep-alive
< Transfer-Encoding: chunked
<
{ [data not shown]
* Connection #0 to host localhost left intact
{
  "status": [
    {
      "now": 1399233463088
    }
  ],
  "bgs": [
    {
      "y": "156",
      "x": 1399231359000,
      "d": "05/04/2014 12:22:39 PM"
    },
    {
      "y": "154",
      "x": 1399231659000,
      "d": "05/04/2014 12:27:39 PM"
    },
    {
      "y": "152",
      "x": 1399231959000,
      "d": "05/04/2014 12:32:39 PM"
    },
    {
      "y": "151",
      "x": 1399232259000,
      "d": "05/04/2014 12:37:39 PM"
    },
    {
      "y": "150",
      "x": 1399232559000,
      "d": "05/04/2014 12:42:39 PM"
    }
  ]
}
This commit is contained in:
Ben West
2014-05-04 12:57:16 -07:00
parent 42d259bdb8
commit 9dcab2f8f7
2 changed files with 18 additions and 2 deletions
+2 -2
View File
@@ -1,4 +1,4 @@
{
"url": "YOUR_MONGODB_URL",
"collection": "YOUR_COLLECTION_NAME"
"url": null,
"collection": null
}
+16
View File
@@ -21,6 +21,7 @@ var patientData = [];
var now = new Date().getTime();
var fs = require('fs');
var mongoClient = require('mongodb').MongoClient;
var pebble = require('./lib/pebble');
var cgmData = [];
////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -34,6 +35,11 @@ var server = require('http').createServer(function serverCreator(request, respon
var sys = require("sys");
// Grab the URL requested by the client and parse any query options
var url = require('url').parse(request.url, true);
if (url.path.indexOf('/pebble') === 0) {
request.with_collection = with_collection;
pebble.pebble(request, response);
return;
}
// Serve file using node-static
staticServer.serve(request, response, function clientHandler(err) {
@@ -90,6 +96,8 @@ var FIVE_MINUTES = 300000;
var FORTY_MINUTES = 2400000;
var TWO_DAYS = 172800000;
var DB = require('./database_configuration.json');
DB.url = DB.url || process.env.CUSTOMCONNSTR_mongo;
DB.collection = DB.collection || process.env.CUSTOMCONNSTR_mongo_collection;
var DB_URL = DB.url;
var DB_COLLECTION = DB.collection;
@@ -106,6 +114,14 @@ var alarms = {
"urgent_alarm": new Alarm("Urgent", 0.10)
};
function with_collection (fn) {
mongoClient.connect(DB_URL, function (err, db) {
if (err) throw err;
var collection = db.collection(DB_COLLECTION);
fn(err, collection);
});
}
function update() {
now = Date.now();