Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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

});
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #react #cors #error
ADD COMMENT
Topic
Name
2+3 =