-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker.js
35 lines (30 loc) · 903 Bytes
/
worker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
self.addEventListener('install', function () {
self.skipWaiting()
})
self.addEventListener('activate', function (event) {
event.waitUntil(self.clients.claim())
})
self.addEventListener('fetch', (event) => {
const { request } = event
// We are only interested in navigation requests.
if (request.mode === 'navigate' && request.destination === 'document') {
const url = new URL(request.url)
// Having a predicate is a good idea so we don't end up
// redirecting from everywhere on the site.
if (url.pathname === '/nested') {
const destination = new URL(
url.pathname + url.search,
'http://localhost:8080'
)
return event.respondWith(
new Response(null, {
status: 301,
headers: {
// Construct a regular redirect response.
Location: destination,
},
})
)
}
}
})