Use self hosted cors -anywhere website to fetch data got 403 error

993 Views Asked by At

I am trying to use the following link to fetch data: https://cross-origin-boyan.herokuapp.com/http://universities.hipolabs.com/search?

It works fine when I test it locally but It throw me error after I publish the website using vercel. It give me 403 error.

For the server.js file for cors-every :

const corsProxy = require("cors-anywhere");

// Listen on a specific host via the HOST environment variable.
const host = process.env.HOST || "0.0.0.0";
// Listen on a specific port via the PORT environment variable.
const port = process.env.PORT || 8080;

corsProxy
    .createServer({
        originWhitelist: [
            "http://localhost:3000",
            "http://localhost:3001",
            "https://btg-code-challenge.vercel.app/",
        ],
        requireHeader: ["origin", "x-requested-with"],
        removeHeaders: ["cookie", "cookie2"],
    })
    .listen(port, host, () => {
        console.log("Running CORS Anywhere on " + host + ":" + port);
    });

In the originWhitelist, I already added my website link. Does anyone have any idea what cause issue here?

Here is the information about my request:

curl 'https://cross-origin-boyan.herokuapp.com/http://universities.hipolabs.com/search' \
  -H 'Connection: keep-alive' \
  -H 'sec-ch-ua: "Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36' \
  -H 'Accept: */*' \
  -H 'Origin: https://btg-code-challenge.vercel.app' \
  -H 'Sec-Fetch-Site: cross-site' \
  -H 'Sec-Fetch-Mode: cors' \
  -H 'Sec-Fetch-Dest: empty' \
  -H 'Referer: https://btg-code-challenge.vercel.app/' \
  -H 'Accept-Language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7,fr;q=0.6' \
  --compressed
0

There are 0 best solutions below