diff options
author | Lars-Dominik Braun <lars@6xq.net> | 2018-03-16 15:06:38 +0100 |
---|---|---|
committer | Lars-Dominik Braun <lars@6xq.net> | 2018-03-16 15:06:38 +0100 |
commit | 5d1bd2891183e93f43f5fdb67e0ffcefabcc8eed (patch) | |
tree | 2b77d24e40bf5d6cdbead12e6dfa9f6d062150fa /swayback/static | |
parent | d187373fd3b8f3aa16af8998f4e6481bb4505e60 (diff) | |
download | swayback-master.tar.gz swayback-master.tar.bz2 swayback-master.zip |
Diffstat (limited to 'swayback/static')
-rw-r--r-- | swayback/static/sw.js | 57 |
1 files changed, 0 insertions, 57 deletions
diff --git a/swayback/static/sw.js b/swayback/static/sw.js deleted file mode 100644 index 56889c0..0000000 --- a/swayback/static/sw.js +++ /dev/null @@ -1,57 +0,0 @@ -self.addEventListener('install', function(event) { - console.log ('installed service worker', event); - self.skipWaiting(); -}); -/* load stuff through service worker immediately? XXX: only debugging? */ -self.addEventListener('activate', async function() { - if (self.registration.navigationPreload) { - // Enable navigation preloads! - await self.registration.navigationPreload.enable(); - } /*event => { - event.waitUntil(clients.claim());*/ -}); - -self.addEventListener('fetch', function(event) { - let origreq = event.request; - console.log ('fetch event', origreq.url, event); - let url = new URL (origreq.url); - url.protocol = 'https:'; - url.port = 443; - url.hash = ''; - if (url.hostname.endsWith ('.swayback.localhost')) { - url.hostname = url.hostname.slice (0, url.hostname.length-'.swayback.localhost'.length); - } - console.log ('orig url', url); - /* should contain everything we cannot use in the actual request (i.e. url and method) */ - let body = { - 'url': url.href, - 'method': origreq.method, - }; - let headers = { - 'Content-Type': 'application/json', - }; - /* add a few well-known request headers */ - let origheaders = origreq.headers; - if (origheaders.has ('accept')) { - headers['Accept'] = origreq.headers.get ('accept'); - } - console.log ('sending', body, headers); - let req = new Request ('http://swayback.localhost:5000/raw', - {method: 'POST', body: JSON.stringify (body), headers: headers, - mode: 'cors'}); - - event.respondWith ( - fetch(req) - .then(function (response) { - // response may be used only once - // we need to save clone to put one copy in cache - // and serve second one - let responseClone = response.clone(); - console.log ('got resp', responseClone); - return response; - }) - .catch (function () { - console.log ('nope'); - }) - ); -}); |