Giter Site home page Giter Site logo

devanabinaya / worker-cors-anywhere Goto Github PK

View Code? Open in Web Editor NEW

This project forked from seenko/worker-cors-anywhere

0.0 0.0 0.0 75 KB

๐Ÿ—บ A Cloudflare Worker that enables CORS Anywhere for any requested resource. ๐Ÿ—บ

License: GNU General Public License v2.0

JavaScript 100.00%

worker-cors-anywhere's Introduction

Deploy to Cloudflare Workers

โš’๐Ÿ—บ worker-cors-anywhere ๐Ÿ—บโš’

A Cloudflare Worker that proxies any request and injects certain headers that allows the resource to be accessed from cross origins.

This worker allows any fully qualified URL to be proxied, if for some reason an invalid URL is provided, it will return a 400 Bad Request response containing the faulty URL string.

How to Use

Once you have this Cloudflare Worker up and running, you can just prepend its url to whatever resource needs CORS.

const corsProxy = 'https://worker.example.com/'

// This is a direct request, which will be blocked.
myRealRequest('https://blocked.cors.net/resource.jpg?id=1234')

// This is a proxied request, which will _not_ be blocked.
myRealRequest(`${corsProxy}https://blocked.cors.net/resource.jpg?id=1234`)

function myRealRequest(url) {
  fetch(url).then(response => myProcessingFunction(response))
}

Injected Headers

Constant Headers - Headers that will always be returned in the response

Header Value
Access-Control-Allow-Origin *
Access-Control-Expose-Headers *

Variable Headers - These headers have special behaviors depending if they are used or not during the request

Header Behavior
Access-Control-Max-Age-Override Value is cloned into Access-Control-Max-Age
Access-Control-Request-Methods Value is cloned into Access-Control-Allow-Methods
Access-Control-Request-Headers Value is cloned into Access-Control-Request-Headers

Environment Variables

These are the environment variables that are currently supported

Environment Variable Description Response when Triggered
WCA_DESTINATION_HOSTNAME_ALLOW_LIST Comma separated list of domains that are allowed to be proxied 403 Forbidden
WCA_DESTINATION_HOSTNAME_BLOCK_LIST Comma separated list of domains that are blocked from being proxied 403 Forbidden
WCA_REQUIRE_ORIGIN If set to true, either the Origin or X-Requested-With headers are required 400 Bad Request
WCA_ORIGIN_HOSTNAME_ALLOW_LIST Comma separated list of origin domains that are allowed to request a proxied resource 403 Forbidden
WCA_ORIGIN_HOSTNAME_BLOCK_LIST Comma separated list of origin domains that are blocked from requesting a proxied resource 403 Forbidden

โš ๏ธ Dependencies Disclaimer โš ๏ธ

This project currently has only two dependencies, this is because of the current bugged state of the built-in runtime URL library, which causes URLs to be improperly parsed, example:
Input: https://worker-cors-anywhere.example.com/https://www.google.com/
Output: https://worker-cors-anywhere.example.com/https:/www.google.com/ (It loses a / from the first // found in the URL path)

Therefore, whatwg-url is used as a URL substitute and webpack to build the project into a single Cloudflare Workers compatible script.

Wrangler

To generate using wrangler

wrangler generate projectname https://github.com/Seenko/worker-cors-anywhere

Further documentation for Wrangler can be found here.

worker-cors-anywhere's People

Contributors

seenko avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.