Skip to content

Commit c29a27e

Browse files
author
Jason Calabrese
committed
Merge branch 'release/0.4.0'
2 parents 1cc9c61 + 6c038f6 commit c29a27e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1127
-154
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@ my.env
88
*.env
99
static/bower_components/
1010
.*.sw?
11+
.DS_Store
1112

12-
.vagrant
13+
.vagrant
14+
/iisnode
15+
/web.config

Procfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: node server.js

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ cgm-remote-monitor (a.k.a. NightScout)
55
[![Dependency Status](https://david-dm.org/nightscout/cgm-remote-monitor.png)](https://david-dm.org/nightscout/cgm-remote-monitor)
66
[![Gitter chat](https://badges.gitter.im/nightscout.png)](https://gitter.im/nightscout/public)
77

8+
[![Deploy to Heroku](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy)
9+
810
This acts as a web-based CGM (Continuous Glucose Montinor) to allow
911
multiple caregivers to remotely view a patients glucose data in
1012
realtime. The server reads a MongoDB which is intended to be data

app.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "CGM Remote Monitor",
3+
"repository": "https://github.com/nightscout/cgm-remote-monitor",
4+
"env": {
5+
"MONGO_COLLECTION": {
6+
"description": "The mongo collection to connect to.",
7+
"value": "nightscout"
8+
}
9+
},
10+
"addons": [
11+
"mongolab"
12+
]
13+
}

bin/post-devicestatus.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
3+
curl -H "Content-Type: application/json" -XPOST 'http://localhost:1337/api/v1/devicestatus/' -d '{
4+
"uploaderBattery": 55
5+
}'

bin/post-treatment.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
3+
curl -H "Content-Type: application/json" -XPOST 'http://localhost:1337/api/v1/treatments/' -d '{
4+
"enteredBy": "Dad",
5+
"eventType":"Site Change",
6+
"glucoseValue": 322,
7+
"glucoseType": "sensor",
8+
"carbsGiven": 0,
9+
"insulinGiven": 1.25,
10+
"notes": "Argh..."
11+
}'

bower.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
{
22
"name": "nightscout",
3-
"version": "0.3.5",
3+
"version": "0.4.0",
44
"dependencies": {
5+
"angularjs": "1.3.0-beta.19",
6+
"bootstrap": "~3.2.0",
57
"d3": "3.4.3",
68
"jquery": "2.1.0",
79
"jQuery-Storage-API": "~1.7.2",

env.js

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,41 @@ function config ( ) {
2121

2222
env.version = software.version;
2323
env.name = software.name;
24-
env.DISPLAY_UNITS = process.env.DISPLAY_UNITS || 'mg/dl';
25-
env.PORT = process.env.PORT || 1337;
26-
env.mongo = process.env.MONGO_CONNECTION || process.env.CUSTOMCONNSTR_mongo;
27-
env.mongo_collection = process.env.CUSTOMCONNSTR_mongo_collection || 'entries';
28-
env.settings_collection = process.env.CUSTOMCONNSTR_mongo_settings_collection || 'settings';
24+
25+
env.DISPLAY_UNITS = readENV('DISPLAY_UNITS', 'mg/dl');
26+
env.PORT = readENV('PORT', 1337);
27+
env.mongo = readENV('MONGO_CONNECTION') || readENV('MONGO') || readENV('MONGOLAB_URI');
28+
env.mongo_collection = readENV('MONGO_COLLECTION', 'entries');
29+
env.settings_collection = readENV('MONGO_SETTINGS_COLLECTION', 'settings');
30+
env.treatments_collection = readENV('MONGO_TREATMENTS_COLLECTION', 'treatments');
31+
env.devicestatus_collection = readENV('MONGO_DEVICESTATUS_COLLECTION', 'devicestatus');
32+
33+
env.enable = readENV('ENABLE');
34+
2935
var shasum = crypto.createHash('sha1');
30-
var useSecret = (process.env.API_SECRET && process.env.API_SECRET.length > 0);
36+
37+
/////////////////////////////////////////////////////////////////
38+
// A little ugly, but we don't want to read the secret into a var
39+
/////////////////////////////////////////////////////////////////
40+
var useSecret = (readENV('API_SECRET') && readENV('API_SECRET').length > 0);
3141
env.api_secret = null;
3242
// if a passphrase was provided, get the hex digest to mint a single token
3343
if (useSecret) {
34-
if (process.env.API_SECRET.length < consts.MIN_PASSPHRASE_LENGTH) {
44+
if (readENV('API_SECRET').length < consts.MIN_PASSPHRASE_LENGTH) {
3545
var msg = ["API_SECRET should be at least", consts.MIN_PASSPHRASE_LENGTH, "characters"];
3646
var err = new Error(msg.join(' '));
3747
// console.error(err);
3848
throw err;
3949
process.exit(1);
4050
}
41-
shasum.update(process.env.API_SECRET);
51+
shasum.update(readENV('API_SECRET'));
4252
env.api_secret = shasum.digest('hex');
4353
}
54+
55+
// For pushing notifications to Pushover.
56+
env.pushover_api_token = readENV('PUSHOVER_API_TOKEN');
57+
env.pushover_user_key = readENV('PUSHOVER_USER_KEY') || readENV('PUSHOVER_GROUP_KEY');
58+
4459
// TODO: clean up a bit
4560
// Some people prefer to use a json configuration file instead.
4661
// This allows a provided json config to override environment variables
@@ -51,8 +66,19 @@ function config ( ) {
5166
env.mongo = DB_URL;
5267
env.mongo_collection = DB_COLLECTION;
5368
env.settings_collection = DB_SETTINGS_COLLECTION;
54-
var STATIC_FILES = __dirname + '/static/';
55-
env.static_files = process.env.NIGHTSCOUT_STATIC_FILES || STATIC_FILES;
69+
env.static_files = readENV('NIGHTSCOUT_STATIC_FILES', __dirname + '/static/');
70+
5671
return env;
5772
}
73+
74+
function readENV(varName, defaultValue) {
75+
//for some reason Azure uses this prefix, maybe there is a good reason
76+
var value = process.env['CUSTOMCONNSTR_' + varName]
77+
|| process.env['CUSTOMCONNSTR_' + varName.toLowerCase()]
78+
|| process.env[varName]
79+
|| process.env[varName.toLowerCase()];
80+
81+
return value || defaultValue;
82+
}
83+
5884
module.exports = config;

lib/api/devicestatus/index.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
'use strict';
2+
3+
var consts = require('../../constants');
4+
5+
function configure (app, wares, devicestatus) {
6+
var express = require('express'),
7+
api = express.Router( );
8+
9+
// invoke common middleware
10+
api.use(wares.sendJSONStatus);
11+
// text body types get handled as raw buffer stream
12+
api.use(wares.bodyParser.raw( ));
13+
// json body types get handled as parsed json
14+
api.use(wares.bodyParser.json( ));
15+
// also support url-encoded content-type
16+
api.use(wares.bodyParser.urlencoded({ extended: true }));
17+
18+
// List settings available
19+
api.get('/devicestatus/', function(req, res) {
20+
devicestatus.list(function (err, profiles) {
21+
return res.json(profiles);
22+
});
23+
});
24+
25+
function config_authed (app, api, wares, devicestatus) {
26+
27+
api.post('/devicestatus/', /*TODO: auth disabled for quick UI testing... wares.verifyAuthorization, */ function(req, res) {
28+
var obj = req.body;
29+
devicestatus.create(obj, function (err, created) {
30+
if (err)
31+
res.sendJSONStatus(res, consts.HTTP_INTERNAL_ERROR, 'Mongo Error', err);
32+
else
33+
res.json(created);
34+
});
35+
});
36+
37+
}
38+
39+
if (app.enabled('api') || true /*TODO: auth disabled for quick UI testing...*/) {
40+
config_authed(app, api, wares, devicestatus);
41+
}
42+
43+
return api;
44+
}
45+
46+
module.exports = configure;
47+

lib/api/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
function create (env, entries, settings) {
3+
function create (env, entries, settings, treatments, devicestatus) {
44
var express = require('express'),
55
app = express( )
66
;
@@ -18,6 +18,14 @@ function create (env, entries, settings) {
1818
app.enable('api');
1919
}
2020

21+
if (env.enable) {
22+
env.enable.toLowerCase().split(' ').forEach(function (value) {
23+
var enable = value.trim();
24+
console.info("enabling feature:", enable);
25+
app.enable(enable);
26+
});
27+
}
28+
2129
app.set('title', [app.get('name'), 'API', app.get('version')].join(' '));
2230

2331
// Start setting up routes
@@ -29,6 +37,8 @@ function create (env, entries, settings) {
2937
// Entries and settings
3038
app.use('/', require('./entries/')(app, wares, entries));
3139
app.use('/', require('./settings/')(app, wares, settings));
40+
app.use('/', require('./treatments/')(app, wares, treatments));
41+
app.use('/', require('./devicestatus/')(app, wares, devicestatus));
3242

3343
// Status
3444
app.use('/', require('./status')(app, wares));

0 commit comments

Comments
 (0)