我正在构建我正在构建的应用程序的构建过程(使用Ext JS +另一个应用程序的后端)并尝试查看是否存在更改本地URL的“最佳实践”方法(例如data / my -data.json)到我的开发服务器的后端,然后到我的生产服务器的后端。
在我的商店中,我目前有以下代码:
Ext.define('APP.store.DataRecords', {
extend: 'Ext.data.Store',
model: 'APP.model.DataRecord',
autoLoad: true,
proxy: {
type: 'ajax',
api: {
read: 'data/data-records.json',
update: 'data/update-data-records.json'
},
reader: {
type: 'json',
root: 'records',
successProperty: 'success'
}
}
});
运行sencha build命令后,理想情况下我希望将Store转换为这样的内容:
Ext.define('APP.store.DataRecords', {
extend: 'Ext.data.Store',
model: 'APP.model.DataRecord',
autoLoad: true,
proxy: {
type: 'ajax',
api: {
read: 'http://mydevserver/.../data-records.json',
update: 'http://mydevserver/.../update-data-records.json'
},
reader: {
type: 'json',
root: 'records',
successProperty: 'success'
}
}
});
我想如果没有任何“直接”方法,我需要构建一个额外的脚本,首先重新映射我的所有URL,然后调用sencha编译器。
PS 我知道通常这一切都是通过使用“相对”网址透明地进行的,但我对后端进行了一些限制,这会阻止这种情况。
思想?
提前致谢!
答案 0 :(得分:1)
我建议您在连接到商店时不要使用完整的网址。如果您正在使用Ajax呼叫并尝试转到不同的域名,则此类呼叫将被视为跨站点呼叫,浏览器将阻止它们。
答案 1 :(得分:0)
在你的app.json
中
/**
* override objects for setting build environment specific
* settings.
*/
"production": {
"api_url": "http://example.com"
},
"testing": {
"api_url": "http://localhost:3000"
},
"development": {
"api_url": "http://localhost:3000"
},
在商店的代理配置
中
proxy: {
type: 'rest',
url: Ext.manifest.api_url + '/products',
format: 'json',
withCredentials: true,
useDefaultXhrHeader: false,
reader: {
type: 'json',
rootProperty: '',
totalProperty: ''
},
writer: {
type: 'json'
}
}