reactjs - redux isomorphic fetch Access-Control-Allow-Origin -


i have written redux application running locally using webpack-dev-server. (port 8080). trying connect web service running locally @ port 9000.

my code connect web service follows

return fetch(`http://localhost:9000/movies/${dimensionname.tolowercase()}list`)   .then(response => response.json())   .then(json =>     dispatch(receiveddimensionattributessuccess(dimensionname, json))   )   .catch(error =>     dispatch(receiveddimensionattributeserror(dimensionname, error))   ); 

this receives error

fetch api cannot load http://localhost:9000/movies/yearlist. no 'access- control-allow-origin' header present on requested resource. origin  'http://localhost:8080' therefore not allowed access. if opaque response  serves needs, set request's mode 'no-cors' fetch resource  cors disabled. 

i googled problem , found thread

access control allow origin header not present fetch api call

but don't solution involved switching different library/middleware altogether.

how can solve problem isomorphic fetch library.

look @ me,this works

you must use

let header = new headers({         'access-control-allow-origin':'*',         'content-type': 'multipart/form-data' }); 

instead of

let defaultoptions = {     url:'',     method:'post',     mode: 'cors',     headers:{         'access-control-allow-origin':'*'     },     body:null, }; 

to enable cors


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -