Skip to content

Commit

Permalink
Merge branch 'wip/onlinestatus' of https://github.com/sulkaharo/cgm-r…
Browse files Browse the repository at this point in the history
…emote-monitor into wip/onlinestatus
  • Loading branch information
jasoncalabrese committed Sep 2, 2017
2 parents d17d69e + b0a8463 commit 325e307
Show file tree
Hide file tree
Showing 25 changed files with 225 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: node_js
sudo: required
node_js:
- 6
- 8.1.4
matrix:
fast_finish: true
services:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ test:

travis:
NODE_ENV=test ${MONGO_SETTINGS} \
${ISTANBUL} cover ${MOCHA} --report lcovonly -- --timeout 30000 -R tap ${TESTS}
${ISTANBUL} cover ${MOCHA} --report lcovonly -- --timeout 50000 -R tap ${TESTS}

docker_release:
# Get the version from the package.json file
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ Clone this repo then install dependencies into the root of the project:
$ npm install
```

If deploying the software to Microsoft Azure, you must set *WEBSITE_NODE_DEFAULT_VERSION* in the app settings to *8.1.4* or the site deployment will fail. Other hosting environments do not require this setting.

# Usage

The data being uploaded from the server to the client is from a
Expand Down
19 changes: 19 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,22 @@ var compression = require('compression');
var bodyParser = require('body-parser');
var prettyjson = require('prettyjson');

var path = require('path');
var fs = require('fs');

function create(env, ctx) {
var app = express();
var appInfo = env.name + ' ' + env.version;
app.set('title', appInfo);
app.enable('trust proxy'); // Allows req.secure test on heroku https connections.

app.set('view engine', 'ejs');
// this allows you to render .html files as templates in addition to .ejs
app.engine('html', require('ejs').renderFile);
app.engine('appcache', require('ejs').renderFile);
app.set("views", path.join(__dirname, "views/"));

app.locals.cachebuster = fs.readFileSync(process.cwd() + '/tmp/cacheBusterToken').toString().trim();

if (ctx.bootErrors && ctx.bootErrors.length > 0) {
app.get('*', require('./lib/booterror')(ctx));
Expand Down Expand Up @@ -50,6 +60,15 @@ function create(env, ctx) {
}));
// app.use(bodyParser({limit: 1048576 * 50, extended: true }));


app.get("/", (req, res) => {
res.render("index.html", {locals: app.locals});
});

app.get("/nightscout.appcache", (req, res) => {
res.render("nightscout.appcache", {locals: app.locals});
});

//if (env.api_secret) {
// console.log("API_SECRET", env.api_secret);
//}
Expand Down
20 changes: 17 additions & 3 deletions lib/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ var receiveDData = require('./receiveddata');

var client = { };

$('#loadingMessageText').html('Connecting to server');

client.hashauth = require('../hashauth').init(client, $);

client.headers = function headers ( ) {
Expand Down Expand Up @@ -55,16 +57,28 @@ client.init = function init(callback) {
, headers: client.headers()
}).done(function success (serverSettings) {
client.settingsFailed = false;
console.log('Application appears to be online');
$('#centerMessagePanel').hide();
client.load(serverSettings, callback);
}).fail(function fail( ) {
}).fail(function fail(jqXHR, textStatus, errorThrown) {

// check if we couldn't reach the server at all, show offline message
if (jqXHR.readyState == 0) {
console.log('Application appears to be OFFLINE');
$('#loadingMessageText').html('Connecting to Nightscout server failed, retrying every 2 seconds');
window.setTimeout(window.Nightscout.client.init(), 2000);
return;
}

//no server setting available, use defaults, auth, etc
if (client.settingsFailed) {
console.info('Already tried to get settings after auth, but failed');
console.log('Already tried to get settings after auth, but failed');
} else {
client.settingsFailed = true;
language.set('en');
client.translate = language.translate;

// auth failed, hide loader and request for key
$('#centerMessagePanel').hide();
client.hashauth.requestAuthentication(function afterRequest ( ) {
client.init(null, callback);
});
Expand Down
51 changes: 49 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
"start": "node server.js",
"test": "make test",
"env": "env",
"postinstall": "webpack --config webpack.config.js",
"postinstall": "webpack --config webpack.config.js && npm run-script update-buster",
"bundle": "webpack --config webpack.config.js",
"bower": "node node_modules/bower/bin/bower --allow-root install && "
"bower": "node node_modules/bower/bin/bower --allow-root install && ",
"update-buster": "node scripts/generateCacheBuster.js >tmp/cacheBusterToken"
},
"config": {
"blanket": {
Expand All @@ -56,6 +57,7 @@
"css-loader": "^0.28.4",
"cssmin": "^0.4.3",
"d3": "^3.5.17",
"ejs": "^2.5.7",
"errorhandler": "^1.5.0",
"event-stream": "^3.3.4",
"expand-braces": "^0.1.2",
Expand Down Expand Up @@ -84,8 +86,10 @@
"mqtt": "^0.3.13",
"node-cache": "^4.1.1",
"parse-duration": "^0.1.1",
"path": "^0.12.7",
"prettyjson": "^1.2.1",
"pushover-notifications": "^0.2.4",
"random-token": "0.0.8",
"request": "^2.81.0",
"sgvdata": "git://github.com/ktind/sgvdata.git#wip/protobuf",
"share2nightscout-bridge": "git://github.com/bewest/share2nightscout-bridge.git#wip/generalize",
Expand All @@ -101,6 +105,7 @@
},
"devDependencies": {
"benv": "3.3.0",
"clear-require": "^2.0.0",
"istanbul": "~0.4.5",
"mocha": "~3.1.2",
"should": "~11.1.1",
Expand Down
4 changes: 4 additions & 0 deletions scripts/generateCacheBuster.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

var randomToken = require('random-token');
var token = randomToken(16);
console.log(token);
4 changes: 2 additions & 2 deletions static/admin/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ <h1 class="translate">Admin Tools</h1>
<b><span class="translate">Authentication status</span>: </b>
<span id="authentication_placeholder"></span>

<script src="/js/bundle.js?v=0.10.0-dev-20170821"></script>
<script src="/js/bundle.js?v=8.1.4-dev-2017082601"></script>
<script src="/socket.io/socket.io.js"></script>
<script src="/admin/js/admin.js?v=0.10.0-dev-20170821"></script>
<script src="/admin/js/admin.js?v=8.1.4-dev-2017082601"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion static/bgclock.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ <h1 class="bgnow"></h1>
<h1 class="clock"></h1>
</div>
<script src="/api/v1/status.js"></script>
<script src="/js/bundle.js?v=0.10.0-dev-20170821"></script>
<script src="/js/bundle.js?v=8.1.4-dev-2017082601"></script>
<script type="text/javascript">
function query ( ) {
console.log('query');
Expand Down
2 changes: 1 addition & 1 deletion static/clock-color.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
</main>

<script src="/api/v1/status.js"></script>
<script src="/js/bundle.js?v=0.10.0-dev-20170821"></script>
<script src="/js/bundle.js?v=8.1.4-dev-2017082601"></script>

<script type="text/javascript">

Expand Down
2 changes: 1 addition & 1 deletion static/clock.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ <h1 class="bgnow"></h1>
</div>
</main>
<script src="/api/v1/status.js"></script>
<script src="/js/bundle.js?v=0.10.0-dev-20170821"></script>
<script src="/js/bundle.js?v=8.1.4-dev-2017082601"></script>
<script type="text/javascript">
function query ( ) {
console.log('query');
Expand Down
4 changes: 2 additions & 2 deletions static/food/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ <h1 class="translate">Food Editor</h1>
<span id="authentication_placeholder"></span>
</div>

<script src="/js/bundle.js?v=0.10.0-dev-20170821"></script>
<script src="/js/bundle.js?v=8.1.4-dev-2017082601"></script>
<script src="/socket.io/socket.io.js"></script>
<script src="/food/js/food.js?v=0.10.0-dev-20170821"></script>
<script src="/food/js/food.js?v=8.1.4-dev-2017082601"></script>
</body>
</html>
Binary file modified static/images/launch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 9 additions & 1 deletion static/js/client.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
'use strict';

window.Nightscout.client.init();
$(document).on('online', function() {
console.log('Application got online event, reloading');
window.location.reload();
});

$(document).ready(function() {
console.log('Application got ready event');
window.Nightscout.client.init();
});
4 changes: 2 additions & 2 deletions static/profile/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ <h1 class="translate">Profile Editor</h1>
</form>

<script src="/api/v1/status.js"></script>
<script src="/js/bundle.js?v=0.10.0-dev-20170821"></script>
<script src="/js/bundle.js?v=8.1.4-dev-2017082601"></script>
<script src="/socket.io/socket.io.js"></script>
<script src="/profile/js/profileeditor.js?v=0.10.0-dev-20170821"></script>
<script src="/profile/js/profileeditor.js?v=8.1.4-dev-2017082601"></script>
</body>
</html>
8 changes: 4 additions & 4 deletions static/report/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<meta name="msapplication-config" content="/browserconfig.xml">
<meta name="theme-color" content="#333333">

<link rel="stylesheet" type="text/css" href="/css/report.css?v=0.10.0-dev-20170821" />
<link rel="stylesheet" type="text/css" href="/css/report.css?v=8.1.4-dev-2017082601" />
<link rel="stylesheet" type="text/css" href="/css/ui-lightness/jquery-ui.min.css">

</head>
Expand Down Expand Up @@ -117,9 +117,9 @@ <h1><img src="/images/logo1.png"><span class="translate">Nightscout reporting</s
<hr>
<b><span class="translate">Authentication status</span>: </b><span id="authentication_placeholder"></span>

<script src="/js/bundle.js?v=0.10.0-dev-20170821"></script>
<script src="/js/bundle.js?v=8.1.4-dev-2017082601"></script>
<script src="/socket.io/socket.io.js"></script>
<script src="/report/js/report.js?v=0.10.0-dev-20170821"></script>
<script src="/report/js/flotcandle.js?v=0.10.0-dev-20170821"></script>
<script src="/report/js/report.js?v=8.1.4-dev-2017082601"></script>
<script src="/report/js/flotcandle.js?v=8.1.4-dev-2017082601"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion static/translations/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ <h1><img src="/images/logo1.png"><span class="translate">Nightscout translations
<hr>
<b><span class="translate">Authentication status</span>: </b><span id="authentication_placeholder"></span>

<script src="/js/bundle.js?v=0.10.0-dev-20170821"></script>
<script src="/js/bundle.js?v=8.1.4-dev-2017082601"></script>

<script src="/api/v1/status.js"></script>
<script src="/socket.io/socket.io.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion tests/admintools.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var someData = {

describe('admintools', function ( ) {
var self = this;
this.timeout(10000);
this.timeout(50000);
before(function (done) {
benv.setup(function() {

Expand Down
3 changes: 3 additions & 0 deletions tests/ar2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ describe('ar2', function ( ) {
});

it('should handle alexa requests', function (done) {
var now = Date.now();
var before = now - FIVE_MINS;

ctx.ddata.sgvs = [{mgdl: 100, mills: before}, {mgdl: 105, mills: now}];
var sbx = prepareSandbox();

Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/headless.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function headless (benv, binding) {

function init (opts, callback) {
var localStorage = opts.localStorage || './localstorage';
var htmlFile = opts.htmlFile || __dirname + '/../../static/index.html';
var htmlFile = opts.htmlFile || __dirname + '/../../views/index.html';
var serverSettings = opts.serverSettings || require('./default-server-settings');
var someData = opts.mockAjax || { };
benv.setup(function() {
Expand Down
Loading

0 comments on commit 325e307

Please sign in to comment.