blob: 4e428374bc227191c1bf7ac23d27b820aa56dd9e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
self.addEventListener('fetch', function(event) {
var url = event.request.url;
if (url.indexOf('sample?test') == -1) {
return;
}
event.respondWith(new Promise(function(resolve) {
var headers = [];
for (var header of event.request.headers) {
headers.push(header);
}
event.request.text()
.then(function(result) {
resolve(new Response(JSON.stringify({
method: event.request.method,
mode: event.request.mode,
credentials: event.request.credentials,
headers: headers,
body: result
})));
});
}));
});
|