Created
August 18, 2019 03:47
-
-
Save luandevpro/13a00022c812fd8500f30151005b8fd5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
addEventListener('fetch', event => { | |
event.respondWith(fetchAndApply(event.request)) | |
}) | |
async function fetchAndApply(request) { | |
let uaSuffix = '' | |
const ua = request.headers.get('user-agent') | |
if (ua.match(/iphone/i) || ua.match(/ipod/i)) { | |
uaSuffix = '/mobile' | |
} else if (ua.match(/ipad/i)) { | |
uaSuffix = '/tablet' | |
} | |
return fetch(request.url + uaSuffix, request) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment