Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

cors error in 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))
 }
Comment

react cors error

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));

});
Comment

react cors error

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));

});
Comment

PREVIOUS NEXT
Code Example
Javascript :: select2 disable search 
Javascript :: logic for building calculator using JavaScript without using eval 
Javascript :: angular component between tags 
Javascript :: dangerouslySetInnerHTML did not match error in React 
Javascript :: jquery current timestamp 
Javascript :: nodejs sharp get image size 
Javascript :: get variable name javascript 
Javascript :: node js favicon.ico 
Javascript :: check if element is hidden jquery 
Javascript :: onclick prevent default 
Javascript :: aabb javascript 
Javascript :: js draw square to canvas 
Javascript :: jquery get src of image 
Javascript :: javascript moeda reais 
Javascript :: stop propagation event 
Javascript :: let count = 0;console.log(parseInt("count"+ 1)); 
Javascript :: how to hack the chrome dinosaur game 
Javascript :: node string to json 
Javascript :: how to add react scroll scrollable link 
Javascript :: field options mongoose 
Javascript :: load json 
Javascript :: onclick go to url 
Javascript :: javascript check if two date are ugual 
Javascript :: react interpolation string html 
Javascript :: mysql innodb_buffer_pool_size 
Javascript :: module not found reactstrap 
Javascript :: remove whitespace with regex javascript 
Javascript :: title case a sentence-javascript 
Javascript :: string pop last char js 
Javascript :: javascript clone class prototype 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =