WEBアプリケーションにて、フロント側からajaxを用いて非同期でfluentdにログを吐きたいのですが、うまくjson形式でデータを送れていないのか、400が返ってきてしまいfluentdに格納できていない状態です。
curlコマンドではうまく格納できているためfluentdの設定がおかしいわけではないと思っています。
どのように修正すればよいでしょうか。
fluentd
の設定(td-agen3)
<match access.*> @type copy <store> @type stdout </store> <store> @type elasticsearch host hogehoge.com port 9200 index_name access type_name log </store> </match> <source> @type http port 8888 body_size_limit 32m keepalive_timeout 10s add_remote_addr true format json cors_allow_origins ["http://hogehoge.com"] </source>
curl
コマンド
→ fluentdにきちんとはいる(curl時はcors_allow_origins
未設定)
curl http://hogehoge.com:8888/access.log -d '{"type":"foo", "timestamp":"2013-11-19 00:51:34"}'
フロントでのjQuery
コード(jQuery 3.1.1)
→ POST http://hogehoge.com:8888/access.log 400 (Bad Request)
と出る
<script type="text/javascript"> $(function () { $.ajax({ type : "POST", url : "http://hogehoge.com:8888/access.log", contentType : "application/x-www-form-urlencoded", dataType : 'JSON', data : { "type" : "foo", "timestamp" : "2013-11-19 00:51:34" } }); }); </script>
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。