diff --git a/core/server/admin/app.js b/core/server/admin/app.js index 9093b952b2..0d116698f1 100644 --- a/core/server/admin/app.js +++ b/core/server/admin/app.js @@ -41,6 +41,9 @@ module.exports = function setupAdminApp() { {maxAge: utils.ONE_YEAR_MS, fallthrough: false} )); + // Service Worker for offline support + adminApp.get(/^\/(sw.js|sw-registration.js)$/, require('./serviceworker')); + // Render error page in case of maintenance adminApp.use(maintenance); diff --git a/core/server/admin/serviceworker.js b/core/server/admin/serviceworker.js new file mode 100644 index 0000000000..66f1498d0d --- /dev/null +++ b/core/server/admin/serviceworker.js @@ -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); +};