Skip to content

Commit

Permalink
Merge pull request #5 from nightscout/dev
Browse files Browse the repository at this point in the history
Update Dev 180812
  • Loading branch information
herzogmedia authored Aug 12, 2018
2 parents 1ce59f7 + da11b02 commit dc04d8b
Show file tree
Hide file tree
Showing 62 changed files with 7,337 additions and 9,030 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ coverage/
npm-debug.log
*.heapsnapshot

/tmp
/tmp
14 changes: 10 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
language: node_js
sudo: required
dist: trusty
os: osx
node_js:
- "8"
- "10"
before_install: if [[ `npm --version` != "5.8.0" ]]; then npm install -g npm@latest; npm --version; fi
before_install:
- if [[ `npm --version` != "5.8.0" ]]; then npm install -g npm@latest; npm --version; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; fi
# https://github.com/Homebrew/homebrew-core/issues/26358
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew unlink python; fi
# "brew install" can succeed but return 1 if it has "caveats".
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install mongodb || true; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew services start mongodb; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install docker || true; fi
matrix:
fast_finish: true
services:
Expand Down
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,18 @@ report:
(npm install codacy-coverage && cat ${ANALYZED} | \
YOURPACKAGE_COVERAGE=1 ./node_modules/codacy-coverage/bin/codacy-coverage.js) || echo "NO COVERAGE"

test_onebyone:
python -c 'import os,sys,fcntl; flags = fcntl.fcntl(sys.stdout, fcntl.F_GETFL); fcntl.fcntl(sys.stdout, fcntl.F_SETFL, flags&~os.O_NONBLOCK);'
$(foreach var,$(wildcard tests/*.js),${MONGO_SETTINGS} ${MOCHA} --timeout 30000 --exit --bail -R tap $(var);)

test:
${MONGO_SETTINGS} ${MOCHA} --timeout 30000 -R tap ${TESTS}
${MONGO_SETTINGS} ${MOCHA} --timeout 30000 --exit --bail -R tap ${TESTS}

travis:
NODE_ENV=test ${MONGO_SETTINGS} \
${ISTANBUL} cover ${MOCHA} --report lcovonly -- --timeout 5000 -R tap ${TESTS}
python -c 'import os,sys,fcntl; flags = fcntl.fcntl(sys.stdout, fcntl.F_GETFL); fcntl.fcntl(sys.stdout, fcntl.F_SETFL, flags&~os.O_NONBLOCK);'
# NODE_ENV=test ${MONGO_SETTINGS} \
# ${ISTANBUL} cover ${MOCHA} --report lcovonly -- --timeout 5000 -R tap ${TESTS}
$(foreach var,$(wildcard tests/*.js),${MONGO_SETTINGS} ${MOCHA} --timeout 30000 --exit --bail -R tap $(var);)

docker_release:
# Get the version from the package.json file
Expand Down
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
web: ./node_modules/.bin/forever --minUptime 100 -c node server.js
web: node server.js
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ Community maintained fork of the

Supported configurations:

If you plan to use Nightscout, we recommend using [Heroku](http://openaps.readthedocs.io/en/latest/docs/While%20You%20Wait%20For%20Gear/nightscout-setup.html#nightscout-setup-with-heroku), as Nightscout can reach the usage limits of the free Azure plan and cause it to shut down for hours or days. If you end up needing a paid tier, the $7/mo Heroku plan is also much cheaper than the first paid tier of Azure. Currently, the only added benefit to choosing the $7/mo Heroku plan vs the free Heroku plan is a section showing site use metrics for performance (such as response time). This has limited benefit to the average Nightscout user. In short, Heroku is the free and best option for Nightscout hosting.

- [Nightscout Setup with Heroku] (http://openaps.readthedocs.io/en/latest/docs/While%20You%20Wait%20For%20Gear/nightscout-setup.html#nightscout-setup-with-heroku) (recommended)
- [Nightscout Setup with Microsoft Azure] (http://www.nightscout.info/wiki/faqs-2/azure-2) (not recommended, please
[switch from Azure to Heroku](http://openaps.readthedocs.io/en/latest/docs/While%20You%20Wait%20For%20Gear/nightscout-setup.html#switching-from-azure-to-heroku) )
Expand All @@ -125,7 +127,11 @@ $ npm install

Installation notes for Microsoft Azure, Windows and Node 10:

- If deploying the software to Microsoft Azure, you must set *WEBSITE_NODE_DEFAULT_VERSION* in the app settings to *8.9.0* **before** you deploy the latest Nightscout or the site deployment will likely fail. Other hosting environments do not require this setting.
- If deploying the software to Microsoft Azure, you must set ** in the app settings for *WEBSITE_NODE_DEFAULT_VERSION* and *SCM_COMMAND_IDLE_TIMEOUT* **before** you deploy the latest Nightscout or the site deployment will likely fail. Other hosting environments do not require this setting. Please use:
```
WEBSITE_NODE_DEFAULT_VERSION=8.11.1
SCM_COMMAND_IDLE_TIMEOUT=300
```
- See [install MongoDB, Node.js, and Nightscouton a single Windows system](https://github.com/jaylagorio/Nightscout-on-Windows-Server). if you want to host your Nightscout outside of the cloud. Although the instructions are intended for Windows Server the procedure is compatible with client versions of Windows such as Windows 7 and Windows 10.
- If you deploy to Windows and want to develop or test you need to install [Cygwin] (https://www.cygwin.com/) (use [setup-x86_64.exe] (https://www.cygwin.com/setup-x86_64.exe) and make sure to install `build-essential` package. Test your configuration by executing `make` and check if all tests are ok.
- There may be some issues with Node 10.6.0 or later with Nightscout. Node 10 support will be in the 0.11 release. Please don't use Nightscout with (Node 9 or) Node 10 at this moment.
Expand Down Expand Up @@ -252,6 +258,7 @@ To learn more about the Nightscout API, visit https://YOUR-SITE.com/api-docs.htm
* `SHOW_PLUGINS` - enabled plugins that should have their visualizations shown, defaults to all enabled
* `SHOW_FORECAST` (`ar2`) - plugin forecasts that should be shown by default, supports space delimited values such as `"ar2 openaps"`
* `LANGUAGE` (`en`) - language of Nightscout. If not available english is used
* Currently supported language codes are: bg (Български), cs (Čeština), de (Deutsch), dk (Dansk), el (Ελληνικά), en (English), es (Español), fi (Suomi), fr (Français), he (עברית), hr (Hrvatski), it (Italiano), ko (한국어), nb (Norsk (Bokmål)), nl (Nederlands), pl (Polski), pt (Português (Brasil)), ro (Română), ru (Русский), sk (Slovenčina), sv (Svenska), zh_cn (中文(简体)), zh_tw (中文(繁體))
* `SCALE_Y` (`log`) - The type of scaling used for the Y axis of the charts system wide.
* The default `log` (logarithmic) option will let you see more detail towards the lower range, while still showing the full CGM range.
* The `linear` option has equidistant tick marks, the range used is dynamic so that space at the top of chart isn't wasted.
Expand Down Expand Up @@ -442,7 +449,7 @@ To learn more about the Nightscout API, visit https://YOUR-SITE.com/api-docs.htm
Integration with Amazon Alexa, [detailed setup instructions](lib/plugins/alexa-plugin.md)

##### `speech` (Speech)
Speech synthesis plugin. When enabled, speaks out the blood glucose values, IOB and alarms.
Speech synthesis plugin. When enabled, speaks out the blood glucose values, IOB and alarms. Note you have to set the LANGUAGE setting on the server to get all translated alarms.

##### `cors` (CORS)
Enabled [CORS](https://en.wikipedia.org/wiki/Cross-origin_resource_sharing) so other websites can make request to your Nightscout site, uses these extended settings:
Expand Down
4 changes: 2 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var _ = require('lodash');
var _get = require('lodash/get');
var express = require('express');
var compression = require('compression');
var bodyParser = require('body-parser');
Expand Down Expand Up @@ -29,7 +29,7 @@ function create(env, ctx) {
}

if (env.settings.isEnabled('cors')) {
var allowOrigin = _.get(env, 'extendedSettings.cors.allowOrigin') || '*';
var allowOrigin = _get(env, 'extendedSettings.cors.allowOrigin') || '*';
console.info('Enabled CORS, allow-origin:', allowOrigin);
app.use(function allowCrossDomain(req, res, next) {
res.header('Access-Control-Allow-Origin', allowOrigin);
Expand Down
8 changes: 6 additions & 2 deletions azuredeploy.json
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@
},
"WEBSITE_NODE_DEFAULT_VERSION": {
"type": "string",
"defaultValue": "8.5.0"
"defaultValue": "8.11.1"
}
},
"resources": [{
Expand Down Expand Up @@ -317,8 +317,12 @@
"value": "[parameters('auth_default_roles')]"
}, {
"name": "WEBSITE_NODE_DEFAULT_VERSION",
"value": "8.5.0"
"value": "8.11.1"
}, {
"name": "SCM_COMMAND_IDLE_TIMEOUT",
"value": "300"
}

]
}
},
Expand Down
3 changes: 3 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ selectNodeVersion
# 3. Install npm packages
if [ -e "$DEPLOYMENT_TARGET/package.json" ]; then
cd "$DEPLOYMENT_TARGET"
echo Installing webpack and webpack-command and yargs
eval $NPM_CMD install -g webpack webpack-command
eval $NPM_CMD install yargs
eval $NPM_CMD install --production --scripts-prepend-node-path
exitWithMessageOnError "npm failed"
cd - > /dev/null
Expand Down
17 changes: 11 additions & 6 deletions env.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
'use strict';

var _ = require('lodash');
var _each = require('lodash/each');
var _trim = require('lodash/trim');
var _forIn = require('lodash/forIn');
var _startsWith = require('lodash/startsWith');
var _camelCase = require('lodash/camelCase');

var fs = require('fs');
var crypto = require('crypto');
var consts = require('./lib/constants');
Expand Down Expand Up @@ -168,16 +173,16 @@ function findExtendedSettings (envs) {
return key.toUpperCase().replace('CUSTOMCONNSTR_', '');
}

_.each(env.settings.enable, function eachEnable(enable) {
if (_.trim(enable)) {
_.forIn(envs, function eachEnvPair (value, key) {
_each(env.settings.enable, function eachEnable(enable) {
if (_trim(enable)) {
_forIn(envs, function eachEnvPair (value, key) {
var env = normalizeEnv(key);
if (_.startsWith(env, enable.toUpperCase() + '_')) {
if (_startsWith(env, enable.toUpperCase() + '_')) {
var split = env.indexOf('_');
if (split > -1 && split <= env.length) {
var exts = extended[enable] || {};
extended[enable] = exts;
var ext = _.camelCase(env.substring(split + 1).toLowerCase());
var ext = _camelCase(env.substring(split + 1).toLowerCase());
if (!isNaN(value)) { value = Number(value); }
if (typeof value === 'string' && (value.toLowerCase() === 'on' || value.toLowerCase() === 'true')) { value = true; }
if (typeof value === 'string' && (value.toLowerCase() === 'off' || value.toLowerCase() === 'false')) { value = false; }
Expand Down
7 changes: 4 additions & 3 deletions lib/admin_plugins/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var _ = require('lodash');
var _find = require('lodash/find');
var _each = require('lodash/each');

function init() {
var allPlugins = [
Expand All @@ -12,14 +13,14 @@ function init() {

function plugins(name) {
if (name) {
return _.find(allPlugins, {name: name});
return _find(allPlugins, {name: name});
} else {
return plugins;
}
}

plugins.eachPlugin = function eachPlugin(f) {
_.each(allPlugins, f);
_each(allPlugins, f);
};

plugins.createHTML = function createHTML(client) {
Expand Down
11 changes: 7 additions & 4 deletions lib/api/activity/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
'use strict';

var _ = require('lodash');
var _forEach = require('lodash/forEach');
var _isNil = require('lodash/isNil');
var _isArray = require('lodash/isArray');

var consts = require('../../constants');
var moment = require('moment');

Expand Down Expand Up @@ -36,7 +39,7 @@ function configure(app, wares, ctx) {
ctx.activity.list(req.query, function(err, results) {
var d1 = null;

_.forEach(results, function clean(t) {
_forEach(results, function clean(t) {

var d2 = null;

Expand All @@ -55,7 +58,7 @@ function configure(app, wares, ctx) {
}
});

if (!_.isNil(d1)) res.setHeader('Last-Modified', d1.toUTCString());
if (!_isNil(d1)) res.setHeader('Last-Modified', d1.toUTCString());

if (ifModifiedSince && d1.getTime() <= moment(ifModifiedSince).valueOf()) {
res.status(304).send({
Expand All @@ -75,7 +78,7 @@ function configure(app, wares, ctx) {
function post_response(req, res) {
var activity = req.body;

if (!_.isArray(activity)) {
if (!_isArray(activity)) {
activity = [activity];
};

Expand Down
7 changes: 3 additions & 4 deletions lib/api/alexa/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
'use strict';

var moment = require('moment');
var _ = require('lodash');

var _each = require('lodash/each');

function configure (app, wares, ctx, env) {
var entries = ctx.entries;
Expand All @@ -21,15 +20,15 @@ function configure (app, wares, ctx, env) {
if (plugin.alexa) {
if (plugin.alexa.intentHandlers) {
console.log(plugin.name + ' is Alexa enabled');
_.each(plugin.alexa.intentHandlers, function (route) {
_each(plugin.alexa.intentHandlers, function (route) {
if (route) {
ctx.alexa.configureIntentHandler(route.intent, route.intentHandler, route.routableSlot, route.slots);
}
});
}
if (plugin.alexa.rollupHandlers) {
console.log(plugin.name + ' is Alexa rollup enabled');
_.each(plugin.alexa.rollupHandlers, function (route) {
_each(plugin.alexa.rollupHandlers, function (route) {
console.log('Route');
console.log(route);
if (route) {
Expand Down
18 changes: 11 additions & 7 deletions lib/api/entries/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
'use strict';

var _ = require('lodash');
var _last = require('lodash/last');
var _isNil = require('lodash/isNil');
var _first = require('lodash/first');
var _includes = require('lodash/includes');

var consts = require('../../constants');
var es = require('event-stream');
var sgvdata = require('sgvdata');
Expand Down Expand Up @@ -77,11 +81,11 @@ function configure(app, wares, ctx) {

function ifModifiedSinceCTX(req, res, next) {

var lastEntry = _.last(ctx.ddata.sgvs);
var lastEntry = _last(ctx.ddata.sgvs);
var lastEntryDate = null;

if (!_.isNil(lastEntry)) {
lastEntryDate = new Date(_.last(ctx.ddata.sgvs).mills);
if (!_isNil(lastEntry)) {
lastEntryDate = new Date(_last(ctx.ddata.sgvs).mills);
res.setHeader('Last-Modified', lastEntryDate.toUTCString());
}

Expand Down Expand Up @@ -140,10 +144,10 @@ function configure(app, wares, ctx) {

res.entries.sort(compare);

var lastEntry = _.first(res.entries);
var lastEntry = _first(res.entries);
var lastEntryDate = null;

if (!_.isNil(lastEntry)) {
if (!_isNil(lastEntry)) {
if (lastEntry.mills) lastEntryDate = new Date(lastEntry.mills);
if (!lastEntry.mills && lastEntry.date) lastEntryDate = new Date(lastEntry.date);
res.setHeader('Last-Modified', lastEntryDate.toUTCString());
Expand Down Expand Up @@ -626,7 +630,7 @@ curl -s -g 'http://localhost:1337/api/v1/times/20{14..15}/T{13..18}:{00..15}'.js
* by default.
*/
function prep_storage(req, res, next) {
if (req.params.storage && _.includes(['entries', 'treatments', 'devicestatus'], req.params.storage)) {
if (req.params.storage && _includes(['entries', 'treatments', 'devicestatus'], req.params.storage)) {
req.storage = ctx[req.params.storage];
} else {
req.storage = ctx.entries;
Expand Down
4 changes: 2 additions & 2 deletions lib/api/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

function create (env, ctx) {
var _ = require('lodash')
var _each = require('lodash/each')
, express = require('express')
, app = express( )
;
Expand All @@ -22,7 +22,7 @@ function create (env, ctx) {

if (env.settings.enable) {
app.extendedClientSettings = ctx.plugins && ctx.plugins.extendedClientSettings ? ctx.plugins.extendedClientSettings(env.extendedSettings) : {};
_.each(env.settings.enable, function (enable) {
_each(env.settings.enable, function (enable) {
console.info('enabling feature:', enable);
app.enable(enable);
});
Expand Down
13 changes: 8 additions & 5 deletions lib/api/properties.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
'use strict';

var _ = require('lodash');
var _isEmpty = require('lodash/isEmpty');
var _filter = require('lodash/filter');
var _pick = require('lodash/pick');

var express = require('express');
var sandbox = require('../sandbox')();

Expand All @@ -22,21 +25,21 @@ function create (env, ctx) {
ctx.plugins.setProperties(sbx);

function notEmpty (part) {
return ! _.isEmpty(part);
return ! _isEmpty(part);
}

var segments = _.filter(req.path.split('/'), notEmpty);
var segments = _filter(req.path.split('/'), notEmpty);

var selected = [ ];

if (segments.length > 0) {
selected = _.filter(segments[0].split(','), notEmpty);
selected = _filter(segments[0].split(','), notEmpty);
}

var result = sbx.properties;

if (selected.length > 0) {
result = _.pick(sbx.properties, selected);
result = _pick(sbx.properties, selected);
}

if (req.query && req.query.pretty) {
Expand Down
Loading

0 comments on commit dc04d8b

Please sign in to comment.