Rob--W / cors-anywhere

CORS Anywhere is a NodeJS reverse proxy which adds CORS headers to the proxied request.
MIT License
8.63k stars 6.03k forks source link

Error 400 when try request to server #225

Closed MrZillaGold closed 4 years ago

MrZillaGold commented 4 years ago

When I try to use such code, an error 400 occurs, I don’t understand what could be the reason, but this is definitely not an axios problem, when using fetch the answer will be the same.

Watching issues axios, I came across the same problem as mine, but they answered that it was a server problem. https://github.com/axios/axios/issues/2814

If you do not use proxy then this code will work fine

// USE ES6 IMPORT/EXPORT

import axios from "axios";

export default class Test {

    options = {
        endpoint: "https://namemc.com",
        proxy: "https://cors-anywhere.herokuapp.com"
    };

    get(options) {
        const {
            proxy, endpoint
        } = this.options;

        return new Promise(async (resolve, reject) => {
                let res;

                await axios.get(`${proxy ? `${proxy}/` : ""}${endpoint}/profile/${options}`)
                    .then(response => res = response)
                    .catch(error => reject(error);

                resolve(res);
        })
    }

}
Rob--W commented 4 years ago

Look at the browser's devtools and/or the network tab of the devtools. Do you see any more specific response headers / response bodies?

I doubt whether the same code from your comment would work, because you are referencing an undefined variable (options) in the template string..

MrZillaGold commented 4 years ago

Found what the problem is, I apologize for the concern.

The code above is working, options are passed when the class method is called

image