1. #1
    Sencha User
    Join Date
    May 2007
    Posts
    74
    Vote Rating
    0
    marceloverdijk is on a distinguished road

      0  

    Default Proxy url suffix and extra parameter for all proxies/request

    Proxy url suffix and extra parameter for all proxies/request


    The Geocongress app contains a proxy like:

    Code:
    Ext.define('GeoCon.store.Bills', {
        extend  : 'Ext.data.Store',
    
        config: {
            model: 'GeoCon.model.Bill',
            groupField: 'state',
    
            proxy: {
                type: 'jsonp',
                url: 'http://api.realtimecongress.org/api/v1/bills.json',
    
                // The following must be set to disable extra parameters being sent to the API, which breaks it
                noCache: false,
                startParam: '',
                pageParam: '',
                limitParam: '',
    
                extraParams: {
                    apikey: '8a341f85c657435989e75c9a83294762'
                },
    
                reader: {
                    type: 'json',
                    rootProperty: 'bills'
                }
            }
        }
    });
    I have a similar use case where my proxies will fetch data from a specific url and I also need to send an API key.

    Instead of hardcoding the API key and server address for each proxy i want to store this information somewhere and automatically use it for all proxies.

    I wonder what the best practices are for this, and maybe somebody knows an example.


    After that I want to extend this and retrieve the server hostname and API key from the local storage.
    This makes it possible to connect to e.g. a preprod server and use different API key per customer.

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,754
    Vote Rating
    828
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    For the different URLs I use a config class and you can do this for the api key. For example:

    Code:
    Ext.define('MyApp.util.Config', {
        singleton : true,
    
        config : {
            api : '....',
            someUrl : 'path/to/service'
        }
    });
    In your app.js you need to setup a path and require the file:

    Code:
    Ext.Loader.setPath({
        MyApp : 'app'
    });
    
    Ext.require([
        'MyApp.util.Config'
    ]);
    Now in your stores you can do this:

    Code:
    Ext.define('MyApp.store.Something', {
        extend : 'Ext.data.Store',
    
        config : {
            type : 'ajax',
            url : MyApp.util.Config.getSomeUrl(),
            extraParams : {
                api : MyApp.util.Config.getApi()
            },
            reader : {
                type : 'json'
            }
        }
    });
    Now you have one place for your api key and urls.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    May 2007
    Posts
    74
    Vote Rating
    0
    marceloverdijk is on a distinguished road

      0  

    Default


    Thanks for the reply! I will look into this.

  4. #4
    Sencha User
    Join Date
    May 2007
    Posts
    74
    Vote Rating
    0
    marceloverdijk is on a distinguished road

      0  

    Default


    PS:

    I had to call it like

    MyApp.util.Config.config.someUrl

    Your example

    MyApp.util.Config.getSomeUrl()

    did not work for me. However this would look nicer.
    Do you think it should work as you suggested?

  5. #5
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,754
    Vote Rating
    828
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Yeah, forgot to mention the initConfig call:

    Code:
    Ext.define('MyApp.util.Config', {
        singleton : true,
    
        config : {
            api : '....',
            someUrl : 'path/to/service'
        },
    
        constructor : function(config) {
            this.initConfig(config);
    
            this.callParent([config]);
        }
    });
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  6. #6
    Sencha User
    Join Date
    May 2007
    Posts
    74
    Vote Rating
    0
    marceloverdijk is on a distinguished road

      0  

    Default


    Thanks for quick reply.
    But unfortunately it's not working for me; see my code below


    Code:
    Ext.define('App.proxy.AppEngine', {
    	extend: 'Ext.data.proxy.JsonP',
    	alias: 'proxy.appengine',
    	config: {
    		extraParams: {
    			secretKey: App.util.Config.getSecretKey() // DOES NOT WORK
    			// secretKey: App.util.Config.config.secretKey WORKS
    		}
    	},
    	constructor: function(config) {
    		this.initConfig(config);
    		this.callParent([config]);
    	},
    	getUrl: function(request) {
    		return App.util.Config.config.serverUrl + this.superclass.getUrl.call(this, request);
    	}
    });
    
    Ext.define('App.util.Config', {
    	singleton: true,
    	config: {
    		secretKey: 'thekey',
    		// serverUrl: 'https://theapp.appspot.com'
    		serverUrl: 'http://localhost:8888'
    	}
    });
    Any idea?

  7. #7
    Sencha User
    Join Date
    May 2007
    Posts
    74
    Vote Rating
    0
    marceloverdijk is on a distinguished road

      0  

    Default


    Actually this is working. I accidently added the constructor to the proxy

    Thanks again for your help.

Thread Participants: 1

Tags for this Thread

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi