feat: move service-worker.js into its own file

v1.18.x
psychobunny 4 years ago
parent 8437130ec2
commit f4d76f1edd

@ -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;
}));
});

@ -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);
@ -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'));
});
};

Loading…
Cancel
Save