Skip to content

Commit f34d85f

Browse files
authored
Fix service worker (#94)
* Fix service worker - fix service worker load by checking for process prior to usage * - string replace logic in sw generator * - update readme, PR template
1 parent d8d4621 commit f34d85f

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ Linting:
88

99
Tests:
1010
<!--Have tests been run locally and passed? If manual tests run, explain what was run below-->
11-
- [ ] E2E tests
1211
- [ ] Manual tests
1312
- [ ] Accessibility tests (no new react-axe errors in console)
1413

1514
Documentation:
1615
<!--Are documentation updates required? Include any mention of updates required below if necessary-->
1716
- [ ] Requires documentation updates
18-
- [ ] Requires Storybook component updates

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,12 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
3939
<td align="center"><a href="https://github.com/rostyk-kanafotskyy"><img src="https://avatars3.githubusercontent.com/u/34774987?v=4" width="100px;" alt=""/><br /><sub><b>Rostyk</b></sub></a><br /><a href="https://github.com/elasticpath/epcc-react-pwa-reference-storefront/commits?author=rostyk-kanafotskyy" title="Code">💻</a></td>
4040
<td align="center"><a href="https://github.com/petro97"><img src="https://avatars3.githubusercontent.com/u/34708483?v=4" width="100px;" alt=""/><br /><sub><b>Dubno Petro</b></sub></a><br /><a href="https://github.com/elasticpath/epcc-react-pwa-reference-storefront/commits?author=petro97" title="Code">💻</a></td>
4141
<td align="center"><a href="https://github.com/yulia-dnistrian"><img src="https://avatars3.githubusercontent.com/u/12392532?v=4" width="100px;" alt=""/><br /><sub><b>yulia-dnistrian</b></sub></a><br /><a href="https://github.com/elasticpath/epcc-react-pwa-reference-storefront/commits?author=yulia-dnistrian" title="Code">💻</a></td>
42-
<td align="center"><a href="https://github.com/skarpyak"><img src="https://avatars3.githubusercontent.com/u/8594755?v=4" width="100px;" alt=""/><br /><sub><b>Sergii Karpiak</b></sub></a><br /><a href="https://github.com/elasticpath/epcc-react-pwa-reference-storefront/commits?author=skarpyak" title="Code">💻</a></td>
42+
<td align="center"><a href="https://github.com/yasiloghmani"><img src="https://avatars0.githubusercontent.com/u/73843686?s=400&u=42ab0036a55d0b65cf4a371b0375779a64763a54&v=4" width="100px;" alt=""/><br /><sub><b>Yasaman Loghmani</b></sub></a><br /><a href="https://github.com/elasticpath/epcc-react-pwa-reference-storefront/commits?author=yasiloghmani" title="Code">💻</a></td>
4343
</tr>
4444
<tr>
45+
<td align="center"><a href="https://github.com/butikden"><img src="https://avatars0.githubusercontent.com/u/33585095?s=400&u=4b005fecdd6f18d4b692fdf1bf572f0666260f41&v=4" width="100px;" alt=""/><br /><sub><b>Denys Butynskyy</b></sub></a><br /><a href="https://github.com/elasticpath/epcc-react-pwa-reference-storefront/commits?author=butikden" title="Code">💻</a></td>
46+
<td align="center"><a href="https://github.com/yurii-khovzun"><img src="https://avatars0.githubusercontent.com/u/68732186?s=400&v=4" width="100px;" alt=""/><br /><sub><b>Yurii Khovzun</b></sub></a><br /><a href="https://github.com/elasticpath/epcc-react-pwa-reference-storefront/commits?author=yurii-khovzun" title="Code">💻</a></td>
47+
<td align="center"><a href="https://github.com/skarpyak"><img src="https://avatars3.githubusercontent.com/u/8594755?v=4" width="100px;" alt=""/><br /><sub><b>Sergii Karpiak</b></sub></a><br /><a href="https://github.com/elasticpath/epcc-react-pwa-reference-storefront/commits?author=skarpyak" title="Code">💻</a></td>
4548
<td align="center"><a href="https://github.com/BonnieEP"><img src="https://avatars3.githubusercontent.com/u/49495842?v=4" width="100px;" alt=""/><br /><sub><b>Bonnie Bishop</b></sub></a><br /><a href="https://ui-components.elasticpath.com" title="Design">🎨</td>
4649
<td align="center"><a href="https://github.com/JenSmith-EP"><img src="https://avatars3.githubusercontent.com/u/58435007?v=4" width="100px;" alt=""/><br /><sub><b>Jen Smith</b></sub></a><br /><a href="https://documentation.elasticpath.com/storefront-react" title="Documentation">📖</a></td>
4750
<td align="center"><a href="https://github.com/mwan-ep"><img src="https://avatars3.githubusercontent.com/u/54115904?v=4" width="100px;" alt=""/><br /><sub><b>Michelle Wan</b></sub></a><br /><a href="https://github.com/elasticpath/epcc-react-pwa-reference-storefront/commits?author=mwan-ep" title="Code">💻</a></td>

build-sw.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@ async function build() {
2828
swSrc: './src/sw-template.js',
2929
swDest: `./${outputPath}/sw-default.js`,
3030
}).then(_ => {
31+
const swConfigString = fs.readFileSync(`./${outputPath}/sw-default.js`, 'utf8');
32+
const swConfigStringMatch = configString.slice(configString.search('endpointURL'), configString.length).match(/'([^']+)'/)[1];
33+
const swConfigEndpointURL = swConfigString.replace('config.endpointURL', process.env.REACT_APP_ENDPOINT_URL || swConfigStringMatch);
34+
fs.writeFileSync(`./${outputPath}/sw-default.js`, swConfigEndpointURL);
3135
console.log('Service worker generated.')
3236
})
3337
}
3438

3539
build();
36-

src/sw-template.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
importScripts('/workbox-sw.js');
2-
importScripts('/config.js');
32

43
workbox.core.skipWaiting();
54
workbox.core.clientsClaim();
@@ -21,7 +20,7 @@ workbox.routing.registerRoute(/https:\/\/fonts.googleapis.com\/.*/, webFontHandl
2120
workbox.routing.registerRoute(/https:\/\/fonts.gstatic.com\/.*/, webFontHandler);
2221

2322
// get-urls-cache
24-
const API = new RegExp('https:\/\/' + config.endpointURL + '\/.*');
23+
const API = new RegExp('https:\/\/' + 'config.endpointURL' + '\/.*');
2524
const apiHandler = new workbox.strategies.NetworkFirst({
2625
cacheName: 'get-urls-cache'
2726
});

0 commit comments

Comments
 (0)