Skip to content

seinick/local-cors-proxy

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Local CORS Proxy

Simple proxy to bypass CORS issues. This was built as a local dev only solution to enable prototyping against existing APIs without having to worry about CORS.

This module was built to solve the issue of getting this error:

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disable

Getting Started

npm install -g local-cors-proxy

Simple Example

API endpoint that we want to request that has CORS issues:

https://www.yourdomain.ie/movies/list

Start Proxy:

lcp --proxyUrl https://www.yourdomain.ie

Then in your client code, new API endpoint:

http://localhost:8010/proxy/movies/list

End result will be a request to https://www.yourdomain.ie/movies/list without the CORS issues!

If you are proxying a location that requires credentials you'll find that you cannot allow origin * and send credentials. To resolve this you can pass the specific origin you want to allow:

lcp --proxyUrl https://www.yourdomain.ie --allowedOrigin http://localhost:3000

Also when dealing with passing credentials, you may need to enable sending the include credentials header.

lcp --proxyUrl https://www.yourdomain.ie --allowedOrigin http://localhost:3000 --includeCredentials

Alternatively you can install the package locally and add a script to your project:

 "scripts": {
   "proxy": "lcp --proxyUrl https://www.yourdomain.ie"
 }

Options

Option Example Default
--proxyUrl https://www.google.ie
--proxyPartial foo proxy
--port 8010 8010
--allowedOrigin http://localhost:3000 *
--includeCredentials true true

About

Simple proxy to bypass CORS issues.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%