Ghost/core/server/admin/serviceworker.js
Felix Rieseberg 53bd7da063 🚀 Allow ServiceWorker /ghost/ scope (#7967)
ServiceWorkers can only control the scope from which they have been served. Our service workers live, like all other files, in an `asset` folder - and could in theory only work on other files in there.

This commit fake-serves our service workers from `/ghost/`, thus allowing them to give everything offline powers.
2017-02-11 14:43:09 +00:00

17 lines
531 B
JavaScript

var debug = require('debug')('ghost:admin:serviceworker'),
path = require('path');
// Route: index
// Path: /ghost/sw.js|sw-registration.js
// Method: GET
module.exports = function adminController(req, res) {
/*jslint unparam:true*/
debug('serviceworker called');
var sw = path.join(__dirname, '..', '..', 'built', 'assets', 'sw.js'),
swr = path.join(__dirname, '..', '..', 'built', 'assets', 'sw-registration.js'),
fileToSend = req.url === '/sw.js' ? sw : swr;
res.sendFile(fileToSend);
};