addEventListener("fetch", event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
try {
const url = new URL(request.url);
if (url.pathname === "/")
return new Response(`
Usage:\n
${url.origin}/<url>
`);
let response = await fetch(request.url.slice(url.origin.length + 1), {
method: request.method,
headers: request.headers,
redirect: "follow",
body: request.body
});
response = new Response(response.body, response)
response.headers.set("Access-Control-Allow-Origin", "*");
return response;
} catch (e) {
return new Response(e.stack || e, {status: 500});
}
}
-
Notifications
You must be signed in to change notification settings - Fork 5
CORS proxy using Cloudflare Workers
License
chebyrash/cors
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
CORS proxy using Cloudflare Workers
Topics
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published