2012-04-23 25 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' 
 
     } 
 
    }

相關問題