| 1234567891011121314151617181920212223242526272829303132333435363738 |
- /**
- * 在 ajax request 前修改url,增加服务端`basePath`
- * `basePath`在`app.json`配置
- */
- Ext.define('saas.override.data.Connection', {
- override: 'Ext.data.Connection',
-
- urlRegexp: /(http|ftp|https):\/\//,
- config: {
- /**
- * @cfg {Object} defaultServerHeaders
- * 与defaultHeaders有区别,只在调用server api的时候才添加的headers
- */
- defaultServerHeaders: null
- },
- privates: {
- setupServerOptions: function(options) {
- var serverOptions = Ext.manifest.server, originUrl = options.url;
- if (serverOptions && serverOptions.basePath && !this.urlRegexp.test(originUrl) &&
- (!serverOptions.urlPattern || new RegExp(serverOptions.urlPattern).test(originUrl))) {
- Ext.Object.merge(options, {
- url: serverOptions.basePath + (originUrl.indexOf('/') == 0 ? '' : '/') + originUrl,
- headers: this.getDefaultServerHeaders()
- });
- }
- }
- },
- request: function(options) {
- if (options && options.url) {
- this.setupServerOptions(options);
- }
- return this.callParent([options]);
- }
- });
-
|