Categorygithub.com/LordotU/local-cors-proxy-go
modulepackage
1.1.0
Repository: https://github.com/lordotu/local-cors-proxy-go.git
Documentation: pkg.go.dev

# README

Local Cors Proxy Go

License Go Report Card

Description

Simple and fast (built on top of fasthttp proxy to bypass CORS issues during prototyping against existing APIs without having to worry about CORS

It was built to solve the issue of getting errors like this:

... has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Limitations

Because func Do(req *Request, resp *Response) error is using for all type of queries it doesn't support redirects!

Usage

Let's imagine API endpoint that we want to request that has CORS issues:

https://licenseapi.herokuapp.com/licenses/mit

Pull Docker image and run a container:

docker pull lordotu/lcp-go

docker run -dti \
  -e LCP_GO_URL=https://licenseapi.herokuapp.com \
  -e LCP_GO_HOST=0.0.0.0 \
  -p 8118:8118 \
  --name lcp-go \
  lordotu/lcp-go

Then in your client code, new API endpoint:

http://localhost:8118/proxy/licenses/mit

End result will be a request to https://licenseapi.herokuapp.com/licenses/mit without the CORS issues!

Alternatively you can build binary (for Linux) from sources with command CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o lcp-go and run it like:

lcp-go --url https://licenseapi.herokuapp.com

Or:

LCP_GO_URL=https://licenseapi.herokuapp.com lcp-go

Configuring

You may set params via command line args or via env variables. All defaults are stored in .env file in the working directory.

Only one argument is required: --url (or LCP_GO_URL if you prefer env variables).

Options

OptionShorthandExampleDefault
--url-uhttps://licenseapi.herokuapp.com
--port-p81198118
--host-h0.0.0.0localhost
--urlSection-sthroughproxy
--serverLogging-ltruefalse
--headers{"X-Requested-With": "lcp-go"}{}
--origin-ohttp://127.0.0.1*
--reflectOrigin-rtruefalse

Environment variables

OptionExampleDefault
LCP_GO_URLhttps://licenseapi.herokuapp.com
LCP_GO_PORT81198118
LCP_GO_HOST0.0.0.0localhost
LCP_GO_URL_SECTIONthroughproxy
LCP_GO_SERVER_LOGGINGtruefalse
LCP_GO_HEADERS{"X-Requested-With": "lcp-go"}{}
LCP_GO_ORIGINhttp://127.0.0.1*
LCP_GO_REFLECT_ORIGINtruefalse

Inspired by: https://github.com/LordotU/corsyusha