1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | 'use strict';
|
9 |
|
10 | module.exports = function createNoopServiceWorkerMiddleware() {
|
11 | return function noopServiceWorkerMiddleware(req, res, next) {
|
12 | if (req.url === '/service-worker.js') {
|
13 | res.setHeader('Content-Type', 'text/javascript');
|
14 | res.send(
|
15 | `// This service worker file is effectively a 'no-op' that will reset any
|
16 | // previous service worker registered for the same host:port combination.
|
17 | // In the production build, this file is replaced with an actual service worker
|
18 | // file that will precache your site's local assets.
|
19 | // See https://github.com/facebookincubator/create-react-app/issues/2272#issuecomment-302832432
|
20 |
|
21 | self.addEventListener('install', () => self.skipWaiting());
|
22 |
|
23 | self.addEventListener('activate', () => {
|
24 | self.clients.matchAll({ type: 'window' }).then(windowClients => {
|
25 | for (let windowClient of windowClients) {
|
26 | // Force open pages to refresh, so that they have a chance to load the
|
27 | // fresh navigation response from the local dev server.
|
28 | windowClient.navigate(windowClient.url);
|
29 | }
|
30 | });
|
31 | });
|
32 | `
|
33 | );
|
34 | } else {
|
35 | next();
|
36 | }
|
37 | };
|
38 | };
|