javascript - How to store Configuration file and read it using React -


i new on react.js have implemented 1 component in fetching data server , use like,

callenterprise:function(tenantid){       fetchdata('http://xxx.xxx.xx.xx:8090/enterprises?tenantid='+tenantid+' &format=json').then(function(enterprises)      {         enterpriseperspectiveactions.getenterprise(enterprises);     }).catch(function()     {         alert("there issue in api call please contact admin");         //componentappdispatcher.handleviewaction({         //    actiontype: metaitemconstants.receive_error,         //    error: 'there problem getting enterprises'         //});     }); }, 

i want store url in configuration file when deployed on testing server or on production have change url on config file not in js file don't know how use configuration file in react.js

can please guide me how can achieve ?

with webpack can put env-specific config externals field in webpack.config.js

externals: {   'config': json.stringify(process.env.env === 'production' ? {     serverurl: "https://myserver.com"   } : {     serverurl: "http://localhost:8090"   }) } 

if want store configs in separate json file, that's possible too, can require file , assign config:

externals: {   'config': json.stringify(production ? require('./config.prod.json') : require('./config.dev.json')) } 

then in modules, can use config:

var config = require('config') fetchdata(config.serverurl + '/enterprises/...') 

not sure if covers use case it's been working pretty us.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -