Created
November 4, 2020 15:14
-
-
Save mcnaveen/cc07fae9c634d6d787f164ff400970eb to your computer and use it in GitHub Desktop.
Cloudflare Workers Dual Parameter
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) { | |
const init = { | |
method: 'GET' | |
} | |
const { searchParams } = new URL(request.url); | |
let param1 = searchParams.get('param1'); | |
let param2 = searchParams.get('param2'); | |
const [output] = await Promise.all([ | |
fetch('https://SITE-URL/app.php?param1=' + param1 + '¶m2=' + param2 , init) | |
]) | |
const btsc = await output.json() | |
const responseInit = { | |
headers: { | |
'Content-Type': 'application/json;charset=UTF-8', | |
'Access-Control-Allow-Origin': '*', | |
'Access-Control-Allow-Methods': 'GET', | |
'Access-Control-Allow-Headers': 'Access-Control-Allow-Headers,Content-Type,Access-Control-Allow-Methods, Authorization, X-Requested-With', | |
'x-content-type-options': 'nosniff', | |
'x-xss-protection': '1; mode=block', | |
'x-frame-options': 'DENY' | |
} | |
} | |
return new Response(JSON.stringify(btsc), responseInit) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment