[英]Deploying Angular 2 (quickstart app) to Google Cloud platform
[英]i can't connect to my elastic search in google cloud platform
我在項目中使用angular 5,並且已經在gcp中設置了elasticsearch和kibana。 一切正常,直到我嘗試將其連接到我的項目。 我知道我必須發送我的憑據,但是它沒有用,我還嘗試在elasticsearch.yml中添加一些CORS,但是完全沒有進展。 因為我的數據庫是firebase,並使用它服務來創建我的彈性搜索實例。 我想將其連接到我的項目中,有人可以幫助我嗎? 謝謝
這是我的代碼:
var client = new elasticsearch.Client({
host: 'http://user:pass@35.225.247.57//elasticsearch',
log: 'trace',
});
client.ping({
// ping usually has a 3000ms timeout
}, function (error) {
if (error) {
console.trace(error);
} else {
console.log('All is well');
}
});
這是服務器的響應
Failed to load http://35.225.247.57//elasticsearch/: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access. The response had HTTP status code 401.
我在elasticsearch.yml中添加了一些CORS
http.cors.allow-origin: "*"
http.cors.allow-credentials: true
http.cors.allow-headers: "X-Requested-With, Content-Type, Content-Length, Authorization"
確保將http.cors.enabled
設置也設置為true
使用合理的值配置http.cors.allow-origin
( *
可以進行測試,但是您不應該使用該值進行生產;將其限制為要使用的來源)
然后,您必須在更改配置后重新啟動ElasticSearch服務。
sudo systemctl stop elasticsearch.service
sudo systemctl start elasticsearch.service
對於它的價值,您還應該禁用純文本HTTP訪問並僅切換到HTTPS。 特別是因為您以明文形式傳遞憑據。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.