Adding some additional console logging to the service worker.

This commit is contained in:
Dan 2017-12-22 20:45:13 -08:00
parent 3940a66c3e
commit 226c88c9da
1 changed files with 4 additions and 0 deletions

View File

@ -76,6 +76,7 @@ self.addEventListener('fetch', (event) => {
}).then((files) => {
// If there's just one result, return it.
if (files.length == 1 && files[0].content) {
console.log('found file content at', files[0].path)
return response(200, 'OK', files[0].content)
}
@ -83,16 +84,19 @@ self.addEventListener('fetch', (event) => {
// doesn't have a trailing slash, redirect. This ensures relative paths work correctly
// for any resources pulled in on the page.
if (files.length > 1 && event.request.url.slice(-1) != '/') {
console.log('redirect to', event.request.url + '/')
return response(302, 'Found', '', {'Location': event.request.url + '/'})
}
// If there are multiple results, look for an index.html page to return.
for (let file of files) {
if (file.path.endsWith('/index.html')) {
console.log('found file content at', file.path)
return response(200, 'OK', file.content)
}
}
console.log('file not found at', event.request.url)
return response(
404, 'Not Found',
Buffer.from('<html><head><title>404 Not Found</title></head><body bgcolor="white"><center><h1>404 Not Found</h1></center><hr><center>Intergalactic</center></body></html>'),