Connection.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /**
  2. * 在 ajax request 前修改url,增加服务端`basePath`
  3. * `basePath`在`app.json`配置
  4. */
  5. Ext.define('saas.override.data.Connection', {
  6. override: 'Ext.data.Connection',
  7. urlRegexp: /(http|ftp|https):\/\//,
  8. config: {
  9. /**
  10. * @cfg {Object} defaultServerHeaders
  11. * 与defaultHeaders有区别,只在调用server api的时候才添加的headers
  12. */
  13. defaultServerHeaders: null
  14. },
  15. privates: {
  16. setupServerOptions: function(options) {
  17. var serverOptions = Ext.manifest.server, originUrl = options.url;
  18. if (serverOptions && serverOptions.basePath && !this.urlRegexp.test(originUrl) &&
  19. (!serverOptions.urlPattern || new RegExp(serverOptions.urlPattern).test(originUrl))) {
  20. Ext.Object.merge(options, {
  21. url: serverOptions.basePath + (originUrl.indexOf('/') == 0 ? '' : '/') + originUrl,
  22. headers: this.getDefaultServerHeaders()
  23. });
  24. }
  25. }
  26. },
  27. request: function(options) {
  28. if (options && options.url) {
  29. this.setupServerOptions(options);
  30. }
  31. return this.callParent([options]);
  32. }
  33. });