1

I don't have access to an external API but I am being blocked out by CORS. I have also enabled "Access-Control-Allow-Origin" in the Axios post config. Most answers are tailored to a local api. How do I get around this?


const auth = {
  username: "xxx",
  password: "xxx",
};

const res = await axios.get(
      `https://api.staging.CORP.dev/stuff/{my-key}/pub_id`,
      { auth },  
        {
        headers: {
          "Content-Type": "application/json",
          "Access-Control-Allow-Origin": "*",
        },
      }
    );
    const pub = res.data.map((pub) => ({ puv_id: pub.id }));
    const data = {
      address: {
        postcode: 'PostCode',
      },
      full_name: 'name',
      email: 'email',
      pub_id: pub
    };
    axios
      .post(
        "https://api.staging.CORP.dev/stuff/{public}/orders",
        data,
        { auth },
        {
          headers: {
            "Content-Type": "application/json",
            "Access-Control-Allow-Origin": "*",
          },
        }
      )
      .then((res) => console.log(res))
      .catch((err) => console.log(err.response));
Sam
  • 232
  • 1
  • 9
  • You can refer to [this](https://stackoverflow.com/a/63734701/17349359) here he has given step by step what to do – DarkForest Mar 01 '22 at 12:47
  • @DarkForest That post is referring to the back end whereas my request is a request on the font end – Sam Mar 01 '22 at 12:50

1 Answers1

-1

You can try adding "proxy": "http://localhost:3000", in your package.json

DarkForest
  • 261
  • 8