Skip to content

Commit

Permalink
feat: move service-worker.js into its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
psychobunny committed Sep 30, 2020
1 parent 8437130 commit f4d76f1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
11 changes: 11 additions & 0 deletions public/src/service-worker.js
@@ -0,0 +1,11 @@
'use strict';

self.addEventListener('fetch', function (event) {
event.respondWith(caches.match(event.request).then(function (response) {
if (!response) {
return fetch(event.request);
}

return response;
}));
});
5 changes: 3 additions & 2 deletions src/routes/meta.js
@@ -1,5 +1,7 @@
'use strict';

const path = require('path');

module.exports = function (app, middleware, controllers) {
app.get('/sitemap.xml', controllers.sitemap.render);
app.get('/sitemap/pages.xml', controllers.sitemap.getPages);
Expand All @@ -10,7 +12,6 @@ module.exports = function (app, middleware, controllers) {
app.get('/css/previews/:theme', controllers.admin.themes.get);
app.get('/osd.xml', controllers.osd.handle);
app.get('/service-worker.js', function (req, res) {
res.set('Content-Type', 'application/javascript');
res.send('self.addEventListener(\'fetch\', event => { event.respondWith( caches.match(event.request).then(response => { if (!response) { return fetch(event.request); } return response; }) ) });');
res.status(200).type('application/javascript').sendFile(path.join(__dirname, '../../public/src/service-worker.js'));
});
};

0 comments on commit f4d76f1

Please sign in to comment.