“reaja o erro CORS” Respostas de código

Erro do CORS no React

componentDidMount() {
  fetch('--------------------------------------------',{
    method: "GET",
    headers: {
      "access-control-allow-origin" : "*",
      "Content-type": "application/json; charset=UTF-8"
    }})
  .then(results => results.json())
  .then(info => {
    const results = info.data.map(x => {
      return {
        id: x.id,
        slug: x.slug,
        name: x.name,
        address_1: x.address_1,
        address_2: x.address_2,
        city: x.city,
        state: x.state,
        postal_code: x.postal_code,
        country_code: x.country_code,
        phone_number: x.phone_number,
      }
    })
    this.setState({warehouses: results, lastPage: info.last_page});
  })
  .then(console.log(this.state.warehouses))
 }
Anand Vasudevan

reaja o erro CORS

package.json
"proxy": "backend localhost i.e., https://localhost:5000"

react frontend
useEffect(() => {
    const res = fetch('/api');
    console.log(res);
  }, [])


backend
app.get('/api', cors(), (req, res) => {
  res.set('Access-Control-Allow-Origin', '*');
  const link = 'https://yourApiLink.com';
  fetch(link).then(response => response.text()).then(text => console.log(text));

});
Distinct Dog

reaja o erro CORS

package.json
"proxy": "backend localhost i.e., https://localhost:5000"

react frontend
useEffect(() => {
    const res = fetch('/api');
    console.log(res);
  }, [])


backend
app.get('/api', cors(), (req, res) => {
  res.set('Access-Control-Allow-Origin', '*');
  const link = 'https://yourApiLink.com';
  fetch(link).then(response => response.text()).then(text => console.log(text));

});
Distinct Dog

Respostas semelhantes a “reaja o erro CORS”

Perguntas semelhantes a “reaja o erro CORS”

Mais respostas relacionadas para “reaja o erro CORS” em JavaScript

Procure respostas de código populares por idioma

Procurar outros idiomas de código