Giter Site home page Giter Site logo

cors-it's Introduction

cors-it

Add CORS to anything!

cors-it is a Node app which acts as a proxy for arbitrary URLs, adding CORS-compliant headers:

access-control-allow-origin: *
access-control-allow-headers: Content-Type, api_key, Authorization
access-control-allow-methods: GET, POST, DELETE, PUT, PATCH, OPTIONS

to the response.

Running cors-it

After cloning this repo, run

$ cd cors-it
$ npm install

to resolve the dependencies. (See How to install npm if you are new to Node and npm.)

Set the PORT environment variable to an available port (for example, 9009; the default is 3000), and run cors-it with

$ PORT=9009 node index.js

Set the URLPARAM environment variable to change the url query parameter to another one (for example, __target; the default is url), and run cors-it with

$ URLPARAM=__target PORT=9009 node index.js

Running cors-it as a background service

Install Forever

$ sudo npm install forever -g

To run cors-it as a background service using Forever:

$ PORT=9009 URLPARAM=__target forever start -o corsit.log -e corsit.err index.js
warn:    --minUptime not set. Defaulting to: 1000ms
warn:    --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
info:    Forever processing file: index.js

To check status of cors-it service:

$ forever list
info:    Forever processes running
data:        uid  command         script   forever pid  id logfile                         uptime      
data:    [0] LwNf /usr/bin/nodejs index.js 4654    4663    /home/cors-it/.forever/LwNf.log 0:0:1:3.373 

To stop cors-it service:

$ forever stop 0
info:    Forever stopped process:
    uid  command         script   forever pid  id logfile                         uptime       
[0] LwNf /usr/bin/nodejs index.js 4654    4663    /home/cors-it/.forever/LwNf.log 0:0:4:25.670

Build using Docker

To build cors-it using a docker container:

docker build -t cors-it .
docker run -p 8081:3000 cors-it

This will start cors-it at http://localhost:8081.

Using cors-it

Pass a URL as the url query parameter

http://localhost:9009/?url=http://petstore.swagger.io/v2/swagger.json

and cors-it will return that resource and its headers and add CORS headers.

You can test your cors-it proxy with curl(1):

curl -D - 'http://localhost:9009/?url=http://petstore.swagger.io/v2/swagger.json'
HTTP/1.1 200 OK
X-Powered-By: Express
access-control-allow-origin: *
access-control-allow-headers: Content-Type, api_key, Authorization
date: Tue, 02 Dec 2014 20:01:43 GMT
access-control-allow-methods: GET, POST, DELETE, PUT, PATCH, OPTIONS
content-type: application/json; charset=utf-8
x-cache: MISS from inetgw47
transfer-encoding: chunked
via: 1.1 inetgw47 (squid)
connection: keep-alive

{"apiVersion":"1.0.0","swaggerVersion":"1.2","apis":[], ... }

If you are using swagger-editor, you can configure the editor to use your cors-it proxy in app/config/defaults.js ; just change the value of importProxyUrl to your host/port, such as

 importProxyUrl: 'http://localhost:9009/?url='

Start cors-it as described above, then start swagger-editor. You should now be able to import a URL into swagger-editor from arbitrary URLs.

cors-it's People

Contributors

jhk avatar mohsen1 avatar sangkeon avatar shatyajeet avatar webron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  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.