question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How do setup an own server with cors-anywhere

See original GitHub issue

Dear @Rob--W thank you very much for your work, it’s a really helpful tool!

One Thing I could not handle yet is to setup an own server to run cors-anywhere. My Plan was to build it as Docker Image and run it in a container on the same server that my website is running which uses cors-anywhere to make API Calls.

Can you help me with the setup? As I think this might be interesting for many cors-anywhere users!

My Setup so far: Server with IP: 12.123.123.12 running a website accessible on Port 80 Docker Container build from your repository with Dockerfile:

FROM node:10.11-alpine

WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install

COPY . .

EXPOSE 8080

CMD [ "node", "server.js" ]

and started on the server with the command:

export CORSANYWHERE_WHITELIST=*
docker run -d -p 8080:8080 --name cors-anywhere -e CORSANYWHERE_WHITELIST=$CORSANYWHERE_WHITELIST cors-anywhere

I tried different things for CORSANYWHERE_WHITELIST like localhost, 127.0.0.1 or 12.123.123.12

with this setup i am able to reach localhost:8080 to see the following message

This API enables cross-origin requests to anywhere.

Usage:

/               Shows help
/iscorsneeded   This is the only resource on this host which is served without CORS headers.
/<url>          Create a request to <url>, and includes CORS headers in the response.

If the protocol is omitted, it defaults to http (https if port 443 is specified).

Cookies are disabled and stripped from requests.

Redirects are automatically followed. For debugging purposes, each followed redirect results
in the addition of a X-CORS-Redirect-n header, where n starts at 1. These headers are not
accessible by the XMLHttpRequest API.
After 5 redirects, redirects are not followed any more. The redirect response is sent back
to the browser, which can choose to follow the redirect (handled automatically by the browser).

The requested URL is available in the X-Request-URL response header.
The final URL, after following all redirects, is available in the X-Final-URL response header.


To prevent the use of the proxy for casual browsing, the API requires either the Origin
or the X-Requested-With header to be set. To avoid unnecessary preflight (OPTIONS) requests,
it's recommended to not manually set these headers in your code.


Demo          :   https://robwu.nl/cors-anywhere.html
Source code   :   https://github.com/Rob--W/cors-anywhere/
Documentation :   https://github.com/Rob--W/cors-anywhere/#documentation

but when i try to make API calls with this url prefix i am always getting the same error as response:

Missing required request header. Must specify one of: origin,x-requested-with

I also tried this setup running on my local machine which also does not work.

I am pretty sure that I am just missing a simple thing, if you could help me with this, it would be really great!

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:28 (11 by maintainers)

github_iconTop GitHub Comments

3reactions
Lewiscowles1986commented, Feb 10, 2021

Hi, would you be open to a one-click deploy being added to the repo so others can launch on Heroku or DigitalOcean?

It seems from #301 that Heroku might not be desirable as it might upset them. I Could do the same for Digitalocean, as at least people will have to pay for their own hosting. But maybe it’s not something you are interested in?

(This offer is for @Rob--W not anyone else)

2reactions
Rob--Wcommented, Mar 25, 2020

* is not a valid origin and does not whitelist anything.

If you don’t want to use whitelisting (i.e. you want to allow any origin to make requests through your proxy), then don’t assign any value to the origin whitelist.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Setup your own CORS proxy / Sylvain Lesage - Observable
Setup your own CORS proxy ... The cors-anywhere service is useful to fetch resources that do not allow requests from observablehq.com, but as...
Read more >
cors-anywhere - npm
CORS Anywhere is a NodeJS proxy which adds CORS headers to the proxied request. The url to proxy is literally taken from the...
Read more >
CORS Anywhere Installation on Heroku - YouTube
Another video for Heroku alternative: https://youtu.be/eO-ya4I1LzQDownload Git: https://git-scm.com/downloadsDownload Heroku: ...
Read more >
Setup your own CORS proxy on Heroku - GetTheKT
Access to XMLHttpRequest at 'https://xxx/' from origin 'xxx' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is ...
Read more >
Setup a Node.js CORS Proxy with Caching Support - Medium
Building the Caching Proxy Server · Architecture · Create a CORS-Anywhere internal proxy · Add Express.js layer to proxy the requests · Add...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found