From c8ba723a7e243d77698513692d8a3fea8384d2b5 Mon Sep 17 00:00:00 2001 From: Charlotte Vermandel Date: Thu, 7 Jul 2022 14:41:22 +0200 Subject: [PATCH] Pass client agent to meilisearch-js --- gatsby-node.js | 4 +++- src/agents.js | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 src/agents.js diff --git a/gatsby-node.js b/gatsby-node.js index fff73ce..32d5943 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -1,5 +1,5 @@ const { MeiliSearch } = require('meilisearch') - +const { constructClientAgents } = require('./src/agents') const { validatePluginOptions, validateIndexOptions, @@ -27,6 +27,7 @@ exports.onPostBuild = async function ({ graphql, reporter }, config) { skipIndexing = false, batchSize = 1000, indexes, + clientAgents = [], } = config if (skipIndexing) { @@ -59,6 +60,7 @@ exports.onPostBuild = async function ({ graphql, reporter }, config) { const client = new MeiliSearch({ host: host, apiKey: apiKey, + clientAgents: constructClientAgents(clientAgents), }) const index = client.index(currentIndex.indexUid) diff --git a/src/agents.js b/src/agents.js new file mode 100644 index 0000000..1c5538f --- /dev/null +++ b/src/agents.js @@ -0,0 +1,11 @@ +const { version } = require('../package.json') + +const constructClientAgents = (clientAgents = []) => { + const instantMeilisearchAgent = `Meilisearch Gatsby (v${version})` + + return clientAgents.concat(instantMeilisearchAgent) +} + +module.exports = { + constructClientAgents, +}