-
-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚀 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.
- Loading branch information
1 parent
a341bbd
commit 53bd7da
Showing
2 changed files
with
19 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
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); | ||
}; |