diff --git a/app.js b/app.js index b718e3772e9..16ee906007c 100644 --- a/app.js +++ b/app.js @@ -7,6 +7,7 @@ const bodyParser = require('body-parser'); const path = require('path'); const fs = require('fs'); +const ejs = require('ejs'); function create (env, ctx) { var app = express(); @@ -92,6 +93,15 @@ function create (env, ctx) { } app.locals.cachebuster = cacheBuster; + app.get("/sw.js", (req, res) => { + res.setHeader('Content-Type', 'application/javascript'); + res.send(ejs.render(fs.readFileSync( + require.resolve(`${__dirname}/views/service-worker.js`), + { encoding: 'utf-8' }), + { locals: app.locals} + )); + }); + if (ctx.bootErrors && ctx.bootErrors.length > 0) { app.get('*', require('./lib/server/booterror')(ctx)); return app; @@ -178,12 +188,6 @@ function create (env, ctx) { app.use("/clock", clockviews); - app.get("/appcache/*", (req, res) => { - res.render("nightscout.appcache", { - locals: app.locals - }); - }); - app.use('/api', bodyParser({ limit: 1048576 * 50 }), apiRoot); diff --git a/views/adminindex.html b/views/adminindex.html index c9bb631cfeb..9b4ff750d2e 100644 --- a/views/adminindex.html +++ b/views/adminindex.html @@ -26,10 +26,10 @@ - + - + <% include preloadCSS %> @@ -39,8 +39,8 @@ <%- include('partials/authentication-status') %> - - - + + + diff --git a/views/clockviews/shared.html b/views/clockviews/shared.html index cb27b137dfb..beac7dc0f2e 100644 --- a/views/clockviews/shared.html +++ b/views/clockviews/shared.html @@ -40,7 +40,7 @@
- + - - + + + diff --git a/views/index.html b/views/index.html index 153e187b7f7..156aa331325 100644 --- a/views/index.html +++ b/views/index.html @@ -1,696 +1,716 @@ - - manifest="appcache/nightscout-<%= locals.cachebuster %>.appcache" - <% } %>> - - - - - - - Nightscout - - - - - - - - - - - - - - - - - - - - - - - - - -<% include preloadCSS %> - - -
-
-

-

Loading the client

-
-
-
-
-
-
-
-
- <%- include('partials/toolbar') %> - -
- -
-
-
- - -
-
-
- -
-
-
---
-
-
-
-
-
- -
    -
  • Hours:
  • -
  • 2
  • -
  • 3
  • -
  • 4
  • -
  • 6
  • -
  • 12
  • -
  • 24
  • -
  • ...
  • -
-
- -
-
-
-
+ + <% include preloadCSS %> + + + +
+
+

+

Loading the client

+
+
+
+
+
+
+
+
+ <%- include('partials/toolbar') %> + +
+ +
+
+
+ - -
-
- -
- Settings -
-
Units
-
-
-
-
-
Date format
-
-
-
-
-
Language
-
- -
-
-
-
Scale
-
- -
-
-
-
Render Basal
-
- -
-
-
-
Enable Alarms
-
-
-
-
-
- - - mins -
-
- - - mins -
-
-
-
-
Night Mode
-
-
-
-
Edit Mode
-
-
-
-
Show Raw BG Data
-
-
-
-
-
-
Custom Title
-
-
-
-
Theme
-
-
-
-
-
-
Show Plugins
-
-
- - - - <%- include('partials/authentication-status') %> - -
- About -
-
version
-
head
-

-

License: AGPL
-
Copyright © 2017 Nightscout contributors
-

- -
-
+ +
+
+
+ +
+
+
---
+
+
- -
-
-
- Log a Treatment - - - -
- Targets - - -
- -
- Glucose Reading - - - - -
-
- - - -
- - - - - - - - - - -
- - - -
- Event Time - - - - -
- - -
-
+
+
+ +
    +
  • Hours:
  • +
  • 2
  • +
  • 3
  • +
  • 4
  • +
  • 6
  • +
  • 12
  • +
  • 24
  • +
  • ...
  • +
+
+ +
+
+
+
+
+ +
+
+ +
+ Settings +
+
Units
+
+
+
+
+
Date format
+
+
+
+
+
Language
+
+ +
+
+
+
Scale
+
+ +
+
+
+
Render Basal
+
+ +
+
+
+
Enable Alarms
+
+
+
+
+
+ + + mins +
+
+ + + mins +
+
+
+
+
Night Mode
+
+
+
+
Edit Mode
+
+
+
+
Show Raw BG Data
+
+
+
+
+
+
Custom Title
+
+
+
+
Theme
+
+
+
+
+
+
Show Plugins
+
+
+ + + + <%- include('partials/authentication-status') %> + +
+ About +
+
version
+
head
+

+

License: AGPL
+
Copyright © 2017 Nightscout contributors
+

+ +
+
+
+ +
+
+
+ Log a Treatment + + + +
+ Targets + + +
+ +
+ Glucose Reading + + + + +
+
+ + + +
+ + + + + + + + + + +
+ + + +
+ Event Time + + + +
-
- -
- - Bolus Wizard - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - BG: - - - - -
- - - - - - - - - - 0.00 -
- Quickpick: -
- -
- - or - - Add from database - - -
-
-
- - - Carbs: - - g - - - -
- - - COB: - - g - - - -
- - - IOB: - - 0.00 -
- - Other correction: - - -
- - Rounding: - - 0.00 -
- - Calculation is in target range. -
- - - Insulin needed: - - 0.00 -
- - Carbs needed: - - - -
- - Basal rate: - - -
-
- -
- + +
+ +
+ +
+
+
+ + Bolus Wizard + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + BG: + + + + +
+ + + + + + + + + + 0.00 +
+ Quickpick:
- - - - +
- - - - -
- Event Time: - - - - - - + + or + + Add from database + + +
- - - - - - -
- - -
- - +
+ + + Carbs: + + g + + + +
+ + + COB: + + g + + + +
+ + + IOB: + + 0.00 +
+ + Other correction: + + +
+ + Rounding: + + 0.00 +
+ + Calculation is in target range. +
+ + + Insulin needed: + + 0.00 +
+ + Carbs needed: + + + +
+ + Basal rate: + + +
+
+ +
+ +
+ + + + +
+ + + + +
+ Event Time: + + + + + +
+ +
+ + + + +
+ +
+ + +
+ + + + + + + + - - - - diff --git a/views/nightscout.appcache b/views/nightscout.appcache deleted file mode 100644 index 3823f894e5f..00000000000 --- a/views/nightscout.appcache +++ /dev/null @@ -1,37 +0,0 @@ -CACHE MANIFEST - -/images/launch.png -/images/apple-touch-icon-57x57.png -/images/apple-touch-icon-60x60.png -/images/apple-touch-icon-72x72.png -/images/apple-touch-icon-76x76.png -/images/apple-touch-icon-114x114.png -/images/apple-touch-icon-120x120.png -/images/apple-touch-icon-144x144.png -/images/apple-touch-icon-152x152.png -/images/apple-touch-icon-180x180.png -/images/favicon-32x32.png -/images/android-chrome-192x192.png -/images/favicon-96x96.png -/images/favicon-16x16.png -/manifest.json -/images/favicon.ico -/images/mstile-144x144.png -/css/ui-darkness/jquery-ui.min.css?v=<%= locals.cachebuster %> -/css/jquery.tooltips.css?v=<%= locals.cachebuster %> -/audio/alarm.mp3 -/audio/alarm2.mp3 -/css/ui-darkness/images/ui-icons_ffffff_256x240.png -/css/ui-darkness/images/ui-icons_cccccc_256x240.png -/css/ui-darkness/images/ui-bg_inset-soft_25_000000_1x100.png -/css/ui-darkness/images/ui-bg_gloss-wave_25_333333_500x100.png -/css/main.css?v=<%= locals.cachebuster %> -/bundle/js/bundle.app.js?v=<%= locals.cachebuster %> -/bundle/js/bundle.clock.js?v=<%= locals.cachebuster %> -/bundle/js/bundle.report.js?v=<%= locals.cachebuster %> -/socket.io/socket.io.js?v=<%= locals.cachebuster %> -/js/client.js?v=<%= locals.cachebuster %> -/images/logo2.png - -NETWORK: -* diff --git a/views/profileindex.html b/views/profileindex.html index 55a98f19dc4..d915d0c8cc8 100644 --- a/views/profileindex.html +++ b/views/profileindex.html @@ -25,10 +25,10 @@ - + - + <% include preloadCSS %> @@ -166,8 +166,8 @@ <%- include('partials/authentication-status') %> - - - + + + diff --git a/views/reportindex.html b/views/reportindex.html index 546e89daf75..8d02bf08f58 100644 --- a/views/reportindex.html +++ b/views/reportindex.html @@ -23,9 +23,9 @@ - - - + + + <% include preloadCSS %> @@ -122,10 +122,10 @@ <%- include('partials/authentication-status') %> - - - - - + + + + + \ No newline at end of file diff --git a/views/service-worker.js b/views/service-worker.js new file mode 100644 index 00000000000..50e720b1aba --- /dev/null +++ b/views/service-worker.js @@ -0,0 +1,107 @@ +'use strict'; + +var CACHE = '<%= locals.cachebuster %>'; + +const CACHE_LIST = [ + '/', + '/images/launch.png', + '/images/apple-touch-icon-57x57.png', + '/images/apple-touch-icon-60x60.png', + '/images/apple-touch-icon-72x72.png', + '/images/apple-touch-icon-76x76.png', + '/images/apple-touch-icon-114x114.png', + '/images/apple-touch-icon-120x120.png', + '/images/apple-touch-icon-144x144.png', + '/images/apple-touch-icon-152x152.png', + '/images/apple-touch-icon-180x180.png', + '/images/favicon-32x32.png', + '/images/android-chrome-192x192.png', + '/images/favicon-96x96.png', + '/images/favicon-16x16.png', + '/manifest.json', + '/images/favicon.ico', + '/images/mstile-144x144.png', + '/css/ui-darkness/jquery-ui.min.css', + '/css/jquery.tooltips.css', + '/audio/alarm.mp3', + '/audio/alarm2.mp3', + '/css/ui-darkness/images/ui-icons_ffffff_256x240.png', + '/css/ui-darkness/images/ui-icons_cccccc_256x240.png', + '/css/ui-darkness/images/ui-bg_inset-soft_25_000000_1x100.png', + '/css/ui-darkness/images/ui-bg_gloss-wave_25_333333_500x100.png', + '/css/main.css', + '/bundle/js/bundle.app.js', + '/bundle/js/bundle.clock.js', + '/bundle/js/bundle.report.js', + '/socket.io/socket.io.js', + '/js/client.js', + '/images/logo2.png' +]; + +// Open a cache and use `addAll()` with an array of assets to add all of them +// to the cache. Return a promise resolving when all the assets are added. +function precache() { + return caches.open(CACHE).then(function (cache) { + return cache.addAll(CACHE_LIST); + }); +} + +// Open the cache where the assets were stored and search for the requested +// resource. Notice that in case of no matching, the promise still resolves +// but it does with `undefined` as value. +function fromCache(request) { + return caches.open(CACHE).then(function (cache) { + return cache.match(request).then(function (matching) { + return matching || Promise.reject('no-match'); + }); + }); +} + +// Update consists in opening the cache, performing a network request and +// storing the new response data. +function update(request) { + return caches.open(CACHE).then(function (cache) { + return fetch(request).then(function (response) { + return cache.put(request, response); + }); + }); +} + +// On install, cache some resources. +self.addEventListener('install', function(evt) { + //console.log('The service worker is being installed.'); + evt.waitUntil(precache()); +}); + +function inCache(request) { + let found = false; + CACHE_LIST.forEach( function (e) { + if (request.url.endsWith(e)) { + found = true; + } + }); + return found; +} + +self.addEventListener('fetch', function(evt) { + if (!evt.request.url.startsWith(self.location.origin) || CACHE === 'developmentMode' || !inCache(evt.request) || evt.request.method !== 'GET') { + //console.log('Skipping cache for ', evt.request.url); + return void evt.respondWith(fetch(evt.request)); + } + //console.log('Returning cached for ', evt.request.url); + evt.respondWith(fromCache(evt.request)); + evt.waitUntil(update(evt.request)); +}); + +self.addEventListener('activate', (event) => { + event.waitUntil( + caches.keys().then((cacheNames) => { + return cacheNames.filter((cacheName) => CACHE !== cacheName); + }).then((unusedCaches) => { + //console.log('DESTROYING CACHE', unusedCaches.join(',')); + return Promise.all(unusedCaches.map((unusedCache) => { + return caches.delete(unusedCache); + })); + }).then(() => self.clients.claim()) + ); +}); \ No newline at end of file