Connection.js 940 B

1234567891011121314151617181920212223242526272829
  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. });
  16. }
  17. }
  18. },
  19. request: function(options) {
  20. if (options && options.url) {
  21. this.setupServerOptions(options);
  22. }
  23. return this.callParent([options]);
  24. }
  25. });