Connection.js 1.0 KB

1234567891011121314151617181920212223242526272829303132
  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. }
  21. },
  22. request: function(options) {
  23. if (options && options.url) {
  24. this.setupServerOptions(options);
  25. }
  26. return this.callParent([options]);
  27. }
  28. });