# Configuring esFactory host dynamically in AngularJs app

**URL:** <https://discuss.elastic.co/t/configuring-esfactory-host-dynamically-in-angularjs-app/17827>\
**Category:** Elasticsearch\
**Created:** [May 30, 2014, 8:29am UTC](https://discuss.elastic.co/t/configuring-esfactory-host-dynamically-in-angularjs-app/17827 "2014-05-30T08:29:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Keith\_Garrod](https://avatars.discourse-cdn.com/v4/letter/k/59ef9b/32.png) [@Keith\_Garrod](https://discuss.elastic.co/u/Keith_Garrod)\
**Post date:** [May 30, 2014, 8:29am UTC](https://discuss.elastic.co/t/configuring-esfactory-host-dynamically-in-angularjs-app/17827/1 "2014-05-30T08:29:16Z")

</div>

I have an AngularJS app using elasticsearch . It works well, but I have a  
problem deploying to production.

I have a service that looks like this:

angular.module('components.common.elasticSearchFactory',[  
])  
.service('ElasticSearch', function (esFactory, Config) {  
function getHost(){  
return Config.elasticSearchHost;  
}  
return esFactory({  
host: getHost(),  
apiVersion: '1.0',  
// pathPrefix: 'optional pathPrefix',  
secure: false  
});  
});

Config.elasticSearchHost contains an environment-dependent host name  
(development, production, staging etc);

The problem is that Config is created from a database record. The  
elasticSearch service is created before the Config is retrieved. This is a  
common issue with Angular. The way I normally overcome it is with something  
like the 'getHost' function. Normally, this would run when a call is made  
to the service, by which time the Config has been resolved.

The problem here is that getHost() is being run while esFactory is being  
configured, not when the service is being called.

Is there a way to configure the esFactory host/credentials after it has  
been instantiated?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/2ab5b030-e560-4302-8f2a-a096646881f5%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/2ab5b030-e560-4302-8f2a-a096646881f5%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 1:25am UTC](https://discuss.elastic.co/t/configuring-esfactory-host-dynamically-in-angularjs-app/17827/2 "2017-07-06T01:25:53Z")

</div>

Closed on July 6, 2017, 1:25am UTC


