# Elasticsearch-browser not connecting to remote server

**URL:** <https://discuss.elastic.co/t/elasticsearch-browser-not-connecting-to-remote-server/277417>\
**Category:** Elasticsearch\
**Created:** [June 30, 2021, 6:49am UTC](https://discuss.elastic.co/t/elasticsearch-browser-not-connecting-to-remote-server/277417 "2021-06-30T06:49:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ayush28j](https://avatars.discourse-cdn.com/v4/letter/a/e47774/32.png) [@ayush28j](https://discuss.elastic.co/u/ayush28j)\
**Post date:** [June 30, 2021, 6:49am UTC](https://discuss.elastic.co/t/elasticsearch-browser-not-connecting-to-remote-server/277417/1 "2021-06-30T06:49:56Z")

</div>

Hello everyone,  
I have a elasticsearch server running on google compute engine at port 9200 with no problems in firewalls.

When I run this curl command:

curl -u elastic:passwordChanged -H "User-Agent: Mozilla" -H "Origin: [http://localhost:4200](http://localhost:4200)" -i public-ip:9200

```auto
HTTP/1.1 200 OK                                                                                                         
access-control-allow-origin: http://localhost:4200                                                                     
vary: origin                                                                                                            
access-control-allow-credentials: true                                                                                  
content-type: application/json; charset=UTF-8                                                                           
content-length: 541 {                                                                                                                        
"name" : "elasticstash",                                                                                                
"cluster_name" : "elasticsearch",                                                                                       
"cluster_uuid" : "krcKlRl4SVmRI7nV1_NazA",                                                                              
"version" : {                                                                                                             
"number" : "7.13.2",                                                                                                   
"build_flavor" : "default",                                                                                             
"build_type" : "tar",                                                                                                   
"build_hash" : "4d960a0733be83dd2543ca018aa4ddc42e956800", "build_date" : "2021-06-10T21:01:55.251515791Z", "build_snapshot" : false,                                                                                               
"lucene_version" : "8.8.2", "minimum_wire_compatibility_version" : "6.8.0", "minimum_index_compatibility_version" : "6.0.0-beta1"                                                                 
},                                                                                                                      
"tagline" : "You Know, for Search"                                                                                    
}                                                                                                                         

```

As you can see I have enabled http.cors. and allowed all origin.

Now the problem I'm facing is I have an angular project which is trying to connect to this server but am getting

```auto
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:9200/. (Reason: CORS request did not succeed).

```

I'm using elasticsearch-browser library to connect.

```auto
import * as es from "elasticsearch-browser";

export class AppComponent {
  private client: es.Client

  private connect(){
    this.client = new es.Client ({
      node: 'http://external-ip:9200',
      httpAuth: 'elastic:changedPassword'
    });
  }

  constructor(){
    this.connect()
    console.log(this.client.ping())
  }
}

```

It works when the server is running on the same machine as angular, but is for some reason not changing the node ip.

What can I do to fix this?  
I obviously changed the password for security reasons .

---

<div class="post-metadata">

**Author:** ![ayush28j](https://avatars.discourse-cdn.com/v4/letter/a/e47774/32.png) [@ayush28j](https://discuss.elastic.co/u/ayush28j)\
**Post date:** [June 30, 2021, 7:32am UTC](https://discuss.elastic.co/t/elasticsearch-browser-not-connecting-to-remote-server/277417/2 "2021-06-30T07:32:58Z")

</div>

Never mind, it was a stupid issue. I followed some code on some website for setup probably for an older version of the elasticsearch library.  
Now, I just replaced the node with host in this

```auto
 node: 'http://external-ip:9200',

```

and it is working now.

---

<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 28, 2021, 7:33am UTC](https://discuss.elastic.co/t/elasticsearch-browser-not-connecting-to-remote-server/277417/3 "2021-07-28T07:33:01Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
