{"action":"closed","issue":{"url":"https://api.github.com/repos/NekR/offline-plugin/issues/121","repository_url":"https://api.github.com/repos/NekR/offline-plugin","labels_url":"https://api.github.com/repos/NekR/offline-plugin/issues/121/labels{/name}","comments_url":"https://api.github.com/repos/NekR/offline-plugin/issues/121/comments","events_url":"https://api.github.com/repos/NekR/offline-plugin/issues/121/events","html_url":"https://github.com/NekR/offline-plugin/issues/121","id":183923093,"number":121,"title":"Provide options to fetch calls in sw.js","user":{"login":"TimGeisler","id":11179787,"avatar_url":"https://avatars.githubusercontent.com/u/11179787?v=3","gravatar_id":"","url":"https://api.github.com/users/TimGeisler","html_url":"https://github.com/TimGeisler","followers_url":"https://api.github.com/users/TimGeisler/followers","following_url":"https://api.github.com/users/TimGeisler/following{/other_user}","gists_url":"https://api.github.com/users/TimGeisler/gists{/gist_id}","starred_url":"https://api.github.com/users/TimGeisler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TimGeisler/subscriptions","organizations_url":"https://api.github.com/users/TimGeisler/orgs","repos_url":"https://api.github.com/users/TimGeisler/repos","events_url":"https://api.github.com/users/TimGeisler/events{/privacy}","received_events_url":"https://api.github.com/users/TimGeisler/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/NekR/offline-plugin/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/NekR/offline-plugin/milestones/3","html_url":"https://github.com/NekR/offline-plugin/milestones/4.0","labels_url":"https://api.github.com/repos/NekR/offline-plugin/milestones/3/labels","id":1805510,"number":3,"title":"4.0","description":"","creator":{"login":"NekR","id":1189265,"avatar_url":"https://avatars.githubusercontent.com/u/1189265?v=3","gravatar_id":"","url":"https://api.github.com/users/NekR","html_url":"https://github.com/NekR","followers_url":"https://api.github.com/users/NekR/followers","following_url":"https://api.github.com/users/NekR/following{/other_user}","gists_url":"https://api.github.com/users/NekR/gists{/gist_id}","starred_url":"https://api.github.com/users/NekR/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NekR/subscriptions","organizations_url":"https://api.github.com/users/NekR/orgs","repos_url":"https://api.github.com/users/NekR/repos","events_url":"https://api.github.com/users/NekR/events{/privacy}","received_events_url":"https://api.github.com/users/NekR/received_events","type":"User","site_admin":false},"open_issues":5,"closed_issues":12,"state":"open","created_at":"2016-06-02T17:13:21Z","updated_at":"2016-10-22T12:43:25Z","due_on":null,"closed_at":null},"comments":4,"created_at":"2016-10-19T10:24:51Z","updated_at":"2016-10-22T12:43:25Z","closed_at":"2016-10-22T12:43:25Z","body":"Hi,\r\nI managed to set up offline-plugin using service workers successfully.\r\n\r\nHowever, when I add htaccess/htpasswd authentication to the web site hosting the webpack bundle, then I get an error message \"wrong response status\":\r\n\r\n```\r\nsw.js:115 [SW]: Install event\r\nwww.example.com/:1 GET https://www.example.com/demo/offline/?__uncache=9351723014dcb8a99531 401 (Unauthorized)\r\nbundle.js:1 GET https://www.example.com/demo/offline/bundle.js?__uncache=9351723014dcb8a99531 401 (Unauthorized)\r\nsw.js:179 Error: Wrong response status(…)(anonymous function) @ sw.js:179\r\nsw.js:503 Uncaught (in promise) Error: Wrong response status(…)(anonymous function) @ sw.js:503\r\n```\r\n\r\nThe relevant snippet of sw.js is the following:\r\n\r\n```\r\nfunction addAllNormalized(cache, requests, options) {\r\n\t  var bustValue = options && options.bust;\r\n\r\n\t  return Promise.all(requests.map(function (request) {\r\n\t    if (bustValue) {\r\n\t      request = applyCacheBust(request, bustValue);\r\n\t    }\r\n\r\n\t    return fetch(request);\r\n\t  })).then(function (responses) {\r\n\t    if (responses.some(function (response) {\r\n\t      return !response.ok;\r\n\t    })) {\r\n\t      return Promise.reject(new Error('Wrong response status'));\r\n\t    }\r\n\r\n\t    var addAll = responses.map(function (response, i) {\r\n\t      return cache.put(requests[i], response);\r\n\t    });\r\n\r\n\t    return Promise.all(addAll);\r\n\t  });\r\n\t}\r\n```\r\n\r\nIn my case it helps to add the following option to all calls of fetch in the generated sw.js file:\r\n\r\n```\r\nfetch(url, {\r\n  credentials: 'same-origin'\r\n})\r\n```\r\n\r\nThen offline using service workers also works with htaccess/htpasswd authentication in my case.\r\n\r\nIt would be good to extend the API to be able to provide options to fetch calls."}}
{"actor":{"display_login":"NekR"}}