A simple dev HTTP/HTTPS proxy for replacing CORS headers.
Quick Install
Homebrew (macOS | Linux)
If you are on macOS or Linux and using Homebrew, you can install uncors with the following one-liner:
brew install evg4b/tap/uncors
Scoop (Windows)
If you are on Windows and using Scoop, you can install uncors with the following commands:
scoop bucket add evg4b https://github.com/evg4b/scoop-bucket.git
scoop install evg4b/uncors
Binary (Cross-platform)
Download the appropriate version for your platform from UNCORS releases page.
Once downloaded, the binary can be run from anywhere. You don’t need to install it into a global location.
This works well for shared hosts and other systems where you don’t have a privileged account.
Ideally, you should install it somewhere in your PATH
for easy use. /usr/local/bin
is the most probable location.
Docker
We currently offer images for Docker https://hub.docker.com/r/evg4b/uncors
docker run -p 80:3000 evg4b/uncors --from 'http://local.github.com' --to 'https://github.com'
Source
Prerequisite Tools
Fetch from GitHub
UNCORS uses the Go Modules support built into Go 1.11 to build. The easiest way to get started is to clone
UNCORS source code in a directory outside the GOPATH, as in the following example:
mkdir $HOME/src
cd $HOME/src
git clone https://github.com/evg4b/uncors.git
cd uncors
go install -tags release
If you are a Windows user, substitute the $HOME environment variable above with %USERPROFILE%
.
Usage
uncors --http-port 8080 --to 'https://github.com' --from 'http://localhost'
Parameters
--from
- Local host with protocol for to the resource from which proxying will take place.--to
- Target host with protocol for to the resource to be proxy.--http-port
- Local HTTP listened port.--https-port
- Local HTTPS listened port.--cert-file
- Path to HTTPS certificate file.--key-file
- Path to matching for certificate private key.--proxy
- HTTP/HTTPS proxy to provide requests to real server (used system by default).--mocks
- File with defined mocks--debug
- Show debug output.
Mocks
Uncors has endpoint mocks mechanism.
All mocks should be defined in yaml file and passed as parameter --mocks
.
Currently available path, method, queries and headers filters
(for more information see gorilla/mux route matching).
Mocks file example:
- path: /raw-content-endpont
response:
code: 200
raw-content: '
Hello word
'
- path: /file-content-endpont
response:
code: 200
file: ~/hello-word.json
- path: /raw-content-endpont
method: POST
queries:
param1: param 1 value
param2: param 1 value
headers:
header1: header 1 value
header2: header 2 value
response:
code: 200
headers:
header1: header 1 value
header2: header 2 value
raw-content: '
{ "status": "ok" }
'
- path: /file-content-endpont
method: POST
queries:
param1: param 1 value
param2: param 1 value
headers:
header1: header 1 value
header2: header 2 value
response:
code: 200
headers:
header1: header 1 value
header2: header 2 value
file: ~/hello-word.json
How it works
sequenceDiagram
participant Client
participant Uncors
participant Server
alt Handling OPTIONS queries
Client ->> Uncors: Access-Control-Request
Uncors ->> Client: Allow-Control-Request
end
alt Handling Data queries
Client ->> Uncors: GET, POST, PUT... query
Note over Uncors: Replacing url with target<br/> in headers and cookies
Uncors-->>Server: Real GET, POST, PUT... query
Server->>Uncors: Real responce
Note over Uncors: Replacing url with source<br/> in headers and cookies
Uncors-->>Client: Data responce
end