i working on react application . configured proxy using module http-proxy-middleware.
at flags page , website url looks //localhost:9000/flags/all .
when user clicks on button in flags page , need call sparkle(rest service) api , should load result. when call sparkle api , internally website url appending , api call forming http://sgd01d:10700/all/sparkle/flags instead of //sgd01d:10700/sparkle/flags . why "all" appending api call? how solve issue
//server app.use('/sparkle', proxy(proxies.sparkle_config())); //proxy config class proxies { static sparkle_config() { return { target: 'http://sgd01d:10700', // target host changeorigin: true // needed virtual hosted sites }; } } export default proxies; //react action //redux-thunk export function loadflags() { return function(dispatch) { dispatch(beginajaxcall()); const promise = axios({url: 'sparkle/v1/api/flag', timeout: 20000, method: 'get', responsetype: 'json'}); promise.then(function(flags) { dispatch(loadflagssuccess(flags)); }).catch(function(error) { throw(error); }); }; }
it looks problem because relative paths in api call. call api axios absolute path:
const promise = axios({url: '/sparkle/v1/api/flag', timeout: 20000, method: 'get', responsetype: 'json'});
Comments
Post a Comment