我是react.js的新手我实现了一个组件,我从服务器获取数据并使用它,如,
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 was some issue in API Call please contact Admin");
//ComponentAppDispatcher.handleViewAction({
// actionType: MetaItemConstants.RECEIVE_ERROR,
// error: 'There was a problem getting the enterprises'
//});
});
},
Run Code Online (Sandbox Code Playgroud)
我想将Url存储在配置文件中,所以当我在测试服务器或生产上部署它时,我只需更改配置文件中的url而不是js文件,但我不知道如何在react.js中使用配置文件
任何人都可以指导我如何实现这一目标?
我正在尝试从graphql-ruby中的resolve方法访问url helpers 以生成类似的字段.我知道我可以这样做:url
EventType = GraphQL::ObjectType.define do
field :url, !types.String do
resolve ->(event, _args, _ctx) do
Rails.application.routes.url_helpers.event_path event
end
end
end
Run Code Online (Sandbox Code Playgroud)
我知道include Rails.application.routes.url_helpers在你的模型中可以避免为每个调用添加前缀但是如何使用graphql-ruby执行此操作?
另外,如果我打电话event_url,它没有主机和端口.显然,我想避免添加host: request.host到每个帮助程序调用.