Connection.js 1.0 KB

123456789101112131415161718192021222324252627282930313233
  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. privates: {
  9. setupServerOptions: function(options) {
  10. var serverOptions = Ext.manifest.server, originUrl = options.url;
  11. if (serverOptions && serverOptions.basePath && !this.urlRegexp.test(originUrl) &&
  12. (!serverOptions.urlPattern || new RegExp(serverOptions.urlPattern).test(originUrl))) {
  13. Ext.apply(options, {
  14. url: serverOptions.basePath + (originUrl.indexOf('/') == 0 ? '' : '/') + originUrl,
  15. headers: {
  16. 'Authorization': ' '
  17. }
  18. });
  19. }
  20. return url;
  21. }
  22. },
  23. request: function(options) {
  24. if (options && options.url) {
  25. this.setupServerOptions(options);
  26. }
  27. return this.callParent([options]);
  28. }
  29. });