admin管理员组文章数量:1397184
I am following the Firebase tutorial on how to implement Algolia with Firebase:
I am currently stuck on the indexing part of the tutorial as I have errors ing from the firebase cloud-functions logs.
The error is: TypeError [ERR_HTTP_INVALID_HEADER_VALUE]: Invalid value "undefined" for header "x-algolia-api-key"
How can I fix this error?
Here is my code
const functions = require('firebase-functions');
const algoliasearch = require("algoliasearch");
const ALGOLIA_ID = functions.config().algolia.app_id;
const ALGOLIA_ADMIN_KEY = functions.config().algolia.api_key;
const ALGOLIA_SEARCH_KEY = functions.config().algolia.search_key;
const ALGOLIA_INDEX_NAME = 'users';
const client = algoliasearch(ALGOLIA_ID, ALGOLIA_ADMIN_KEY);
// Update the search index every time a blog post is written.
exports.onUserCreated = functions.firestore.document('path').onCreate((snap, context) => {
// Get the note document
const user = snap.data();
// Add an 'objectID' field which Algolia requires
user.objectID = snap.id;
console.log(user.objectID)
// Write to the algolia index
const index = client.initIndex(ALGOLIA_INDEX_NAME);
return index.saveObject(user);
});
I am following the Firebase tutorial on how to implement Algolia with Firebase: https://firebase.google./docs/firestore/solutions/search
I am currently stuck on the indexing part of the tutorial as I have errors ing from the firebase cloud-functions logs.
The error is: TypeError [ERR_HTTP_INVALID_HEADER_VALUE]: Invalid value "undefined" for header "x-algolia-api-key"
How can I fix this error?
Here is my code
const functions = require('firebase-functions');
const algoliasearch = require("algoliasearch");
const ALGOLIA_ID = functions.config().algolia.app_id;
const ALGOLIA_ADMIN_KEY = functions.config().algolia.api_key;
const ALGOLIA_SEARCH_KEY = functions.config().algolia.search_key;
const ALGOLIA_INDEX_NAME = 'users';
const client = algoliasearch(ALGOLIA_ID, ALGOLIA_ADMIN_KEY);
// Update the search index every time a blog post is written.
exports.onUserCreated = functions.firestore.document('path').onCreate((snap, context) => {
// Get the note document
const user = snap.data();
// Add an 'objectID' field which Algolia requires
user.objectID = snap.id;
console.log(user.objectID)
// Write to the algolia index
const index = client.initIndex(ALGOLIA_INDEX_NAME);
return index.saveObject(user);
});
Share
Improve this question
asked Jul 20, 2020 at 12:59
Elias FizesanElias Fizesan
3051 gold badge6 silver badges19 bronze badges
1 Answer
Reset to default 4Obviously your ALGOLIA_ID
or ALGOLIA_ADMIN_KEY
value is undefined.
You try to use values from functions environment configuration but it does not seem to be there.
In terminal go to your firebase project folder and type
firebase functions:config:get
You should see the output that should look like JSON object. If you don't see algolia
settings, set it like this:
firebase functions:config:set algolia.app_id="YOUR APP ID" algolia.api_key="YOUR API KEY" algolia.search_key="YOUR SEARCH KEY"
More info here: https://firebase.google./docs/functions/config-env
本文标签: javascriptTypeError ERRHTTPINVALIDHEADERVALUE for Algolia with FirebaseStack Overflow
版权声明:本文标题:javascript - TypeError [ERR_HTTP_INVALID_HEADER_VALUE] for Algolia with Firebase - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744151216a2593065.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论