Git Product home page Git Product logo

cors-server.js's Introduction

cors-server.js

A simple CORS proxy server with configurable allowed domains.

QuickStart

  1. Install node
    curl https://webi.sh/node | sh
    source ~/.config/envman/PATH.env
  2. Download and enter the project directory
    git clone https://github.com/dashhive/cors-server.js
    pushd ./cors-server.js/
  3. Run cors-server with config options
    # ./bin/cors-server.js [flags]
    ./bin/cors-server.js --prefix /api/cors/ --port 2677 --domains 'example.com, example.org'
  4. Test with curl
    curl http://localhost:2677/api/cors/example.com
    (browser testing requires https, see below)

Usage

Configuration

You can either set command line flags, or set ENVs. Flags take precedence.

flag ENV example description
--port PORT= 2677 Number
--prefix CORS_PROXY_PREFIX= /api/cors/ URL Path
--domains CORS_ALLOWED_DOMAINS= 'example.com, example.org' URL Hostname

See ./example.env for config options.

Set HTTPS for localhost with Caddy

  1. Install caddy
    curl https://webi.sh/caddy | sh
    source ~/.config/envman/PATH.env
  2. Create ./Caddyfile
    https://localhost:443 {
        handle /api/* {
            reverse_proxy localhost:2677
        }
    }
  3. Run caddy and localhost https will be generated
    caddy run --config ./Caddyfile

Test in a browser console

  1. Open the JavaScript console
    Cmd โŒ˜ + Alt โŒฅ + I
  2. Test it out with fetch
    await fetch("https://localhost/api/cors/example.com/", { mode: "cors" });

Run as a Service

  1. Install Serviceman
    curl https://webi.sh/serviceman | sh
    source ~/.config/envman/PATH.env
  2. Generate and enable service file for cors-server
    sudo env PATH="$PATH" \
        serviceman add --system -- \
            ./bin/cors-server.js --
                --port 2677 \
                --prefix /api/cors/ \
                --domains example.com
  3. Generate and enable service file for caddy
    sudo env PATH="$PATH" \
        serviceman add --system --cap-net-bind -- \
        caddy run --config ./Caddyfile

cors-server.js's People

Stargazers

Saad Azghour avatar

Watchers

Rion Daniel Gull 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.