# No 'Access-Control-Allow-Origin- http plugin logstash

**URL:** https://discuss.elastic.co/t/no-access-control-allow-origin-http-plugin-logstash/69453
**Category:** Logstash
**Created:** [December 19, 2016, 1:43pm UTC](https://discuss.elastic.co/t/no-access-control-allow-origin-http-plugin-logstash/69453 "2016-12-19T13:43:46Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![adhikz](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@adhikz](https://discuss.elastic.co/u/adhikz)
#### Post date: [December 19, 2016, 1:43pm UTC](https://discuss.elastic.co/t/no-access-control-allow-origin-http-plugin-logstash/69453/1 "2016-12-19T13:43:46Z")

</div>

I am current trying to do a JavaScript post to Logstash by using a tcp input.

**JavaScript Post**

```
 xhr = new XMLHttpRequest();
 var url = "http://localhost:5043";
 xhr.open("POST", url, true);
 xhr.setRequestHeader("Content-type", "application/json");
 var data = JSON.stringify({"test" : hello});
 xhr.send(data);

```

**Logstash config file**

```
input {
	tcp {
		port => 5043
	}
}

filter{
}

output {
  stdout { 
		codec => rubydebug
	}
}

```

**Output in console**

```
{
       "message" => "OPTIONS / HTTP/1.1\r",
      "@version" => "1",
    "@timestamp" => "2016-12-15T09:58:54.611Z",
          "host" => "0:0:0:0:0:0:0:1",
          "port" => 55867,
  
}
{
       "message" => "Host: localhost:5043\r",
      "@version" => "1",
    "@timestamp" => "2016-12-15T09:58:54.620Z",
          "host" => "0:0:0:0:0:0:0:1",
          "port" => 55867,
 
}
{
       "message" => "Connection: keep-alive\r",
      "@version" => "1",
    "@timestamp" => "2016-12-15T09:58:54.621Z",
          "host" => "0:0:0:0:0:0:0:1",
          "port" => 55867,
  
}
{
       "message" => "Access-Control-Request-Method: POST\r",
      "@version" => "1",
    "@timestamp" => "2016-12-15T09:58:54.622Z",
          "host" => "0:0:0:0:0:0:0:1",
          "port" => 55867,
    
}
{
       "message" => "Origin: http://atgdev11\r",
      "@version" => "1",
    "@timestamp" => "2016-12-15T09:58:54.623Z",
          "host" => "0:0:0:0:0:0:0:1",
          "port" => 55867,
      
}
{
       "message" => "User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36\r",
      "@version" => "1",
    "@timestamp" => "2016-12-15T09:58:54.626Z",
          "host" => "0:0:0:0:0:0:0:1",
          "port" => 55867,
      
}
{
       "message" => "Access-Control-Request-Headers: content-type\r",
      "@version" => "1",
    "@timestamp" => "2016-12-15T09:58:54.634Z",
          "host" => "0:0:0:0:0:0:0:1",
          "port" => 55867,
    
}
{
       "message" => "Accept: */*\r",
      "@version" => "1",
    "@timestamp" => "2016-12-15T09:58:54.651Z",
          "host" => "0:0:0:0:0:0:0:1",
          "port" => 55867,
   
}
{
       "message" => "Referer: http://test/Welcome.jsp\r",
      "@version" => "1",
    "@timestamp" => "2016-12-15T09:58:54.653Z",
          "host" => "0:0:0:0:0:0:0:1",
          "port" => 55867,
  
}
{
       "message" => "Accept-Encoding: gzip, deflate, sdch, br\r",
      "@version" => "1",
    "@timestamp" => "2016-12-15T09:58:54.719Z",
          "host" => "0:0:0:0:0:0:0:1",
          "port" => 55867,

}
{
       "message" => "Accept-Language: en-US,en;q=0.8\r",
      "@version" => "1",
    "@timestamp" => "2016-12-15T09:58:54.720Z",
          "host" => "0:0:0:0:0:0:0:1",
          "port" => 55867,
   
}

```

I cant seem to see my json data **{"test" : hello}** passing into logstash could there be something wrong with my logstash.config file ? Please help

I have also tried the following :

input {  
http {  
port =\> 5043  
}  
}

I get the following error is broswser : XMLHttpRequest cannot load [http://localhost:5043/](http://localhost:5043/). Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '[http://test/](http://test/)' is therefore not allowed access.

Please guide me in the right direction as to what I need to look at ? I am very new to the ELK stack

Thanks

---

<div class="post-metadata">

### Author: ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)
#### Post date: [December 22, 2016, 6:46am UTC](https://discuss.elastic.co/t/no-access-control-allow-origin-http-plugin-logstash/69453/2 "2016-12-22T06:46:21Z")

</div>

I'm not sure there's a good way around this right now. AJAX requires the preflight check to pass and the http input doesn't respond to those (maybe it should?), and the tcp input isn't meant to be used for HTTP.

---

<div class="post-metadata">

### Author: ![adhikz](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@adhikz](https://discuss.elastic.co/u/adhikz)
#### Post date: [January 18, 2017, 3:04pm UTC](https://discuss.elastic.co/t/no-access-control-allow-origin-http-plugin-logstash/69453/3 "2017-01-18T15:04:54Z")

</div>

Hi @magnusbaeck thank you for your response, sorry for the late reply. After some digging I manage to find a solution to this by adding the following to my logstash.conf file :

**http {**  
host =\> "localhost"  
port =\> 5043  
**response\_headers =\> {**  
"Access-Control-Allow-Origin" =\> "\*"  
"Content-Type" =\> "text/plain"  
"Access-Control-Allow-Headers" =\> "Origin, X-Requested-With, Content-Type, Accept"  
}  
}

I used the http plugin for logstash. Thank you.

---

<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: [February 15, 2017, 3:04pm UTC](https://discuss.elastic.co/t/no-access-control-allow-origin-http-plugin-logstash/69453/4 "2017-02-15T15:04:56Z")

</div>

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