如何将Firebase手电筒集成到我的应用程序中

我正在尝试将Firebase Flashlight与ElasticSearch集成到Node.js应用程序中,以便对我的Firebase集合进行search操作。 我想在api.js中定义我的searchpath(例如: myhost: myport/ search/mycollection/:key )。

问题是myport与ElasticSearch运行的是不同的(9200)。

我想在路线上: myhost: myport/whatever运行我的应用程序,并在路线myhost: myport/ search/mycollection/:key运行search,现在可以在myhost:9200

我如何将它们整合到Express中?

当我configurationElasticSearch时,我使用:

 var config = { host: 'localhost', port: 9200, log: 'trace' }; var esc = new ElasticSearch.Client(config); 

Elastic Search将运行在与Express应用程序不同的端口上,这是正常的。 实际上,你不能在同一个端口上运行两台服务器。

手电筒更像是一个不同的应用程序,你需要在你的服务器上运行。 使用npm startnpm monitor可以在设置configuration文件后启动Flashlight进程。 手电筒将小心为您提供来自Firebase的弹性search数据。

要与Elastic Search交互,只需使用Node模块。 你已经这样做了。 如您所述,弹性search将在端口9200上运行,而Express应用程序将运行在不同的端口上(例如3000 )。

受到Flashlight的启发,我创build了Elasticfire ,它具有Flashlight所没有的一些function(例如,连接),并可以在应用程序中用作库。

 const ElasticFire = require("elasticfire"); // Initialize the ElasticFire instance let ef = new ElasticFire({ // Set the Firebase configuration firebase: { apiKey: "AI...BY", authDomain: "em...d.firebaseapp.com", databaseURL: "https://em...d.firebaseio.com", storageBucket: "em...d.appspot.com", messagingSenderId: "95...36" } // Firebase paths and how to index them in Elasticsearch , paths: [ { // Firebase path path : "articles" // Elasticsearch index and type , index: "articles" , type : "article" // Optional joined fields , joins: [ // The `author` is a field from the article // which points to the `users` collection. { path: "users" , name: "author" } // If we have an array of comment ids, pointing // to another collection, then they will be joined too , { path: "comments" , name: "comments" } ] // Filter out some data , filter: (data, snap) => snap.key !== "_id" } ] }); // Listen for the events emitted by // the ElasticFire instanceand output some data ef.on("error", err => { console.error(err); }).on("index_created", name => { console.log(`${name} created`); }).on("index_updated", name => { console.log(`${name} updated`); }).on("index_deleted", name => { console.log(`${name} deleted`); });