-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide a no-op SW that will be served by the dev environment. (#2276)
* Provide a no-op SW that will be served by the dev environment. * Hide no-op service worker from user
- Loading branch information
1 parent
d76c1b7
commit eadfad2
Showing
4 changed files
with
52 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,40 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
module.exports = function createNoopServiceWorkerMiddleware() { | ||
return function noopServiceWorkerMiddleware(req, res, next) { | ||
if (req.url === '/service-worker.js') { | ||
res.setHeader('Content-Type', 'text/javascript'); | ||
res.send( | ||
`// This service worker file is effectively a 'no-op' that will reset any | ||
// previous service worker registered for the same host:port combination. | ||
// In the production build, this file is replaced with an actual service worker | ||
// file that will precache your site's local assets. | ||
// See /~https://github.com/facebookincubator/create-react-app/issues/2272#issuecomment-302832432 | ||
self.addEventListener('install', () => self.skipWaiting()); | ||
self.addEventListener('activate', () => { | ||
self.clients.matchAll({ type: 'window' }).then(windowClients => { | ||
for (let windowClient of windowClients) { | ||
// Force open pages to refresh, so that they have a chance to load the | ||
// fresh navigation response from the local dev server. | ||
windowClient.navigate(windowClient.url); | ||
} | ||
}); | ||
}); | ||
` | ||
); | ||
} else { | ||
next(); | ||
} | ||
}; | ||
}; |
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