Skip to content

Commit

Permalink
Merge b8cf50e into e63453c
Browse files Browse the repository at this point in the history
  • Loading branch information
jasoncalabrese authored Sep 11, 2017
2 parents e63453c + b8cf50e commit 58dfca5
Show file tree
Hide file tree
Showing 25 changed files with 1,110 additions and 112 deletions.
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
45 changes: 41 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,23 @@ 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));
return app;
Expand Down Expand Up @@ -48,11 +58,38 @@ function create(env, ctx) {
return compression.filter(req, res);
}
}));
// app.use(bodyParser({limit: 1048576 * 50, extended: true }));

//if (env.api_secret) {
// console.log("API_SECRET", env.api_secret);
//}
app.get("/", (req, res) => {
res.render("index.html", {
locals: app.locals
});
});

var appPages = {
"/clock-color.html":"clock-color.html",
"/admin":"adminindex.html",
"/profile":"profileindex.html",
"/food":"foodindex.html",
"/bgclock.html":"bgclock.html",
"/report":"reportindex.html",
"/translations":"translationsindex.html",
"/clock.html":"clock.html"
};

Object.keys(appPages).forEach(function(page) {
app.get(page, (req, res) => {
res.render(appPages[page], {
locals: app.locals
});
});
});

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

app.use('/api/v1', bodyParser({
limit: 1048576 * 50
}), api);
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
Loading

0 comments on commit 58dfca5

Please sign in to comment.