mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
Adds a `Service-Worker-Allowed` header on `assets/src/service-worker.js` URL and uses `scope` option during registration to ensure the service worker is correctly scoped to the entire forum and only the forum.
This commit is contained in:
@@ -788,7 +788,7 @@ app.cacheBuster = null;
|
||||
|
||||
function registerServiceWorker() {
|
||||
if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.register(config.relative_path + '/assets/src/service-worker.js')
|
||||
navigator.serviceWorker.register(config.relative_path + '/assets/src/service-worker.js', { scope: config.relative_path + '/' })
|
||||
.then(function () {
|
||||
console.info('ServiceWorker registration succeeded.');
|
||||
}).catch(function (err) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const nconf = require('nconf');
|
||||
|
||||
module.exports = function (app, middleware, controllers) {
|
||||
app.get('/sitemap.xml', controllers.sitemap.render);
|
||||
@@ -11,7 +12,7 @@ module.exports = function (app, middleware, controllers) {
|
||||
app.get('/manifest.webmanifest', controllers.manifest);
|
||||
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.status(200).type('application/javascript').sendFile(path.join(__dirname, '../../public/src/service-worker.js'));
|
||||
app.get('/assets/src/service-worker.js', function (req, res) {
|
||||
res.status(200).type('application/javascript').set('Service-Worker-Allowed', nconf.get('relative_path') + '/').sendFile(path.join(__dirname, '../../public/src/service-worker.js'));
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user