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