How do setup an own server with cors-anywhere
See original GitHub issueDear @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:
- Created 3 years ago
- Comments:28 (11 by maintainers)
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)
*
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.