2012-04-23 49 views
0

我正在构建我正在构建的应用程序(使用Ext JS +另一个应用程序的后端)的构建过程并尝试查看它是否存在“最佳做法”将本地URL(例如data/my-data.json)更改为我的开发服务器的后端,然后再更改到我的生产服务器的后端。在Ext JS应用程序中部署:更改商店中的URL

在我的商店目前,我有以下代码:

Ext.define('APP.store.DataRecords', { 
    extend: 'Ext.data.Store', 
    model: 'APP.model.DataRecord', 
    autoLoad: true, 

    proxy: { 
     type: 'ajax', 
     api: { 
      read: 'data/data-records.json', 
      update: 'data/update-data-records.json' 
     }, 
     reader: { 
      type: 'json', 
      root: 'records', 
      successProperty: 'success' 
     } 
    } 
}); 

在运行煎茶build命令,我非常希望的商店改造成这样的:

Ext.define('APP.store.DataRecords', { 
    extend: 'Ext.data.Store', 
    model: 'APP.model.DataRecord', 
    autoLoad: true, 

    proxy: { 
     type: 'ajax', 
     api: { 
      read: 'http://mydevserver/.../data-records.json', 
      update: 'http://mydevserver/.../update-data-records.json' 
     }, 
     reader: { 
      type: 'json', 
      root: 'records', 
      successProperty: 'success' 
     } 
    } 
}); 

我想象一下,如果没有任何'直接'的方法,我需要建立一个额外的脚本,首先重新映射我的所有URL,然后调用sencha编译器。

P.S.我明白,通常情况下,这一切都是通过使用'相对'URL来透明地发生的,但是我与我交互的后端有一些限制,这阻止了这一点。

想法?

在此先感谢!

回答

1

我建议不要在连接到商店时使用完整的URL。如果您使用的是Ajax调用,并且正在尝试转到不同的域名,则这些调用将被视为跨网站调用,浏览器会阻止它们。

+1

使用完整的URL肯定会产生问题,但在这情况一应该能够很快地将其从AJAX切换到JSONP。但是,现在我采取了使用相对URL的方法,这可能会导致后续问题。仍然有兴趣听到任何人是否有可能使用的替代方法。 – 2012-04-24 11:38:21

0

在你app.json

/** 
 
    * override objects for setting build environment specific 
 
    * settings. 
 
    */ 
 
    "production": { 
 
     "api_url": "http://example.com" 
 
    }, 
 

 
    "testing": { 
 
     "api_url": "http://localhost:3000" 
 
    }, 
 

 
    "development": { 
 
     "api_url": "http://localhost:3000" 
 
    },

在您的商店的代理配置

proxy: { 
 
     type: 'rest', 
 
     url: Ext.manifest.api_url + '/products', 
 
     format: 'json', 
 
     withCredentials: true, 
 
     useDefaultXhrHeader: false, 
 
     reader: { 
 
     type: 'json', 
 
     rootProperty: '', 
 
     totalProperty: '' 
 
     }, 
 
     writer: { 
 
     type: 'json' 
 
     } 
 
    }

相关问题