Last active
November 29, 2019 02:54
-
-
Save girvan/2ee69ba0f1887aaab1dc8663240ca73c 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(handleRequest(event.request)) | |
}) | |
async function handleRequest(request) { | |
const url = request.url + (request.url.indexOf('?')===-1 ? '?' : '&') | |
const hook1Response = await fetch(url + 'workers_proxy_get=1', request) | |
let api = await hook1Response.text() | |
if(!api.match(/^https?:\/\/[^\s]+$/)) | |
return new Response(api, hook1Response); | |
let apiResponse = await fetch(api) | |
apiResponse = await apiResponse.text() | |
let formData = new FormData() | |
formData.set('html', apiResponse) | |
return fetch(url + 'workers_proxy_response=1', | |
{ headers: request.headers, method:"POST", body:formData }) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment