Git Product home page Git Product logo

cors.io's Introduction

cors.io

a simple cors proxy

Now fully flaskified, and ready for deployment on heroku.

Table of Contents

Supported HTTP Methods

GET Request

$.getJSON('http://cors.io/?' +
    'https://httpbin.org/get?cors=a_problem',
    function (res) {
        console.log(res);
    });
{
    "args": {
        "cors": "a_problem"
    },
    "headers": {
        "Accept": "*/*",
        "Accept-Encoding": "gzip, deflate",
        "Host": "httpbin.org",
        "User-Agent": ""
    },
    "origin": "",
    "url": "https://httpbin.org/get?cors=a_problem"
}

POST Request

application/json

$.ajax({
    method: "POST",
    url: 'https://cors.io/?' + 
        'https://httpbin.org/post',
    headers: {
        'Content-Type': 'application/json'
    },
    data: JSON.stringify({
    	"cors": "a_problem"
    }),
    success: (res) => console.log(res)
});
{
    "args": {}, 
    "data": "{\"cors\":\"a_problem\"}", 
    "files": {}, 
    "form": {}, 
    "headers": {
        "Accept": "*/*", 
        "Accept-Encoding": "gzip, deflate", 
        "Content-Length": "20", 
        "Host": "httpbin.org", 
        "User-Agent": ""
    }, 
    "json": {
        "cors": "a_problem"
    }, 
    "origin": "", 
    "url": "https://httpbin.org/post"
}

application/x-www-form-urlencoded

$.ajax({
    method: "POST",
    url: 'https://cors.io/?' + 
        'https://httpbin.org/post',
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
    },
    data: "cors=a_problem",
    success: (res) => console.log(res)
});
{
    "args": {}, 
    "data": "", 
    "files": {}, 
    "form": {
        "cors": "a_problem"
    }, 
    "headers": {
        "Accept": "*/*", 
        "Accept-Encoding": "gzip, deflate", 
        "Content-Length": "14", 
        "Content-Type": "application/x-www-form-urlencoded", 
        "Host": "httpbin.org", 
        "User-Agent": ""
    }, 
    "json": null, 
    "origin": "", 
    "url": "https://httpbin.org/post"
}

multipart/form-data

var formData = new FormData();
formData.append("cors", "a_problem");

files = $("input[type='file']")[0].files;
for (var i = 0; i < files.length; i++)
    formData.append("file " + (i + 1), files[i]);

$.ajax({
    method: "POST",
    url: 'https://cors.io/?' + 
        'https://httpbin.org/post',
    data: formData,
    processData: false,
    contentType: false,
    success: (res) => console.log(res)
});
{
    "args": {}, 
    "data": "", 
    "files": {
        "file 1": "file 1 content\n",
        "file 2": "file 2 content\n"
    }, 
    "form": {
        "cors": "a_problem"
    }, 
    "headers": {
        "Accept": "*/*", 
        "Accept-Encoding": "gzip, deflate", 
        "Content-Length": "310", 
        "Content-Type": "multipart/form-data; boundary=1c7006cba3bb1825a4294d7fd319942c", 
        "Host": "httpbin.org", 
        "User-Agent": ""
    }, 
    "json": null, 
    "origin": "", 
    "url": "https://httpbin.org/post"
}

OPTIONS Request

There is no purpose in requesting this method manually. However, some javascript libraries such as axios submit an OPTIONS request before the POST request in the case of Content-Type: application/json.

In order to work with that, an OPTIONS request is sent from the website, to itself. This will return the landing page, along with the required to headers in order for CORS to not block the preflight-response.

Deploying on Heroku

  1. First of all begin by forking this reposity. This can be done by clicking the fork button next to the top of repository. Fork

  2. Then create your heroku app under the name you like.

Create App becomes Create App Form

  1. You will be taken to the new app's page, where you can specify the deployment method you wish to use. In our case, GitHub. Connect to GitHub

  2. After connecting to GitHub, search for the name of the fork and Connect it.

Searching Fork becomes Connected Fork

  1. After it has been connected, deploy the branch on Heroku.

Pre Deployment becomes Post Deployment

  1. View your app. App

cors.io's People

Contributors

nizarmah avatar pierce403 avatar

Watchers

 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.