Created
February 21, 2024 17:31
-
-
Save brownie-in-motion/37a239f7004a926601a1710566ffaecc 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
const response = ` | |
globalThis.proxy = (url, opts) => ( | |
fetch('https://moo.flag.sh/json?url=' + encodeURIComponent(url), { | |
method: 'POST', | |
body: JSON.stringify(opts ?? {}), | |
}).then((res) => res.json()) | |
) | |
` | |
export default { | |
async fetch(request, env, ctx) { | |
const { searchParams, pathname } = new URL(request.url) | |
const url = searchParams.get('url') | |
if (!url) return new Response(response.trim(), { | |
headers: { 'content-type': 'application/javascript' }, | |
}) | |
if (pathname === '/json') { | |
const data = await request.json() | |
const response = await fetch(url, data) | |
const map = new Map() | |
for (const [k, v] of response.headers.entries()) { | |
if (!map.has(k)) map.set(k, []) | |
map.get(k).push(v) | |
} | |
return new Response(JSON.stringify({ | |
headers: Object.fromEntries(map), | |
status: response.status, | |
body: (await response.text()), | |
}), { | |
headers: { 'access-control-allow-origin': '*' } | |
}) | |
} else { | |
return new Response(null, { status: 404 }) | |
} | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment