0
보안 된 API 키를 생성하려고하지만 올바르게 생성되지 않은 것 같습니다. API 문서를 따랐습니다. Algolia가 잘못된 보안 API 키를 생성합니다.
이
내가var algoliasearch = require('algoliasearch');
var admin_client = algoliasearch('APP', 'ADMIN_KEY');
var search_client = algoliasearch('APP', 'ONLY_SEARCH_KEY');
var admin_index = admin_client.initIndex('INDEX');
var search_index = search_client.initIndex('INDEX');
admin_index.search('dav', (err, content) => { console.log(err, content) });
//------------------CONSOLE-------------------------------
null { hits:
[ { firstname: 'David',
lastname: 'De Anda',
_tags: [Object],
objectID: '2',
_highlightResult: [Object] } ],
nbHits: 1,
page: 0,
nbPages: 1,
hitsPerPage: 20,
processingTimeMS: 1,
query: 'dav',
params: 'query=dav' }
//-------------------------------------------------
search_index.search('dav', (err, content) => { console.log(err, content) });
//------------------CONSOLE-------------------------------
null { hits:
[ { firstname: 'David',
lastname: 'De Anda',
_tags: [Object],
objectID: '2',
_highlightResult: [Object] } ],
nbHits: 1,
page: 0,
nbPages: 1,
hitsPerPage: 20,
processingTimeMS: 1,
query: 'dav',
params: 'query=dav' }
//-------------------------------------------------
모든 것이 지금까지 작동하는 것 같다 뭘하는지입니다하지만 지금은 일부 보안 API-키
var valid_until = Math.floor(Date.now()/1000) + 3600
var from_admin_api_key = admin_client.generateSecuredApiKey('from_admin', {validUntil: valid_until});
var from_search_api_key = search_client.generateSecuredApiKey('from_search', {validUntil: valid_until});
var sub_admin_client = algoliasearch('APP', from_admin_api_key);
var sub_search_client = algoliasearch('APP', from_search_api_key);
var sub_admin_index = sub_admin_client.initIndex('INDEX');
var sub_search_index = sub_search_client.initIndex('INDEX');
sub_admin_index.search('dav', (err, content) => { console.log(err, content) });
//------------------CONSOLE-------------------------------
{ Error
at success (/app/node_modules/algoliasearch/src/AlgoliaSearchCore.js:334:32)
at process._tickDomainCallback (internal/process/next_tick.js:129:7)
name: 'AlgoliaSearchError',
message: 'Invalid Application-ID or API key',
debugData:
[ { currentHost: 'https://ge24e6css9-dsn.algolia.net',
headers: [Object],
content: '{"params":"query=dav"}',
contentLength: 22,
method: 'POST',
timeouts: [Object],
url: '/1/indexes/INDEX/query',
startTime: 2017-01-13T17:46:42.519Z,
endTime: 2017-01-13T17:46:44.038Z,
duration: 1519,
statusCode: 403 } ],
statusCode: 403 } undefined
//-------------------------------------------------
sub_search_index.search('dav', (err, content) => { console.log(err, content) });
//------------------CONSOLE-------------------------------
{ Error
at success (/app/node_modules/algoliasearch/src/AlgoliaSearchCore.js:334:32)
at process._tickDomainCallback (internal/process/next_tick.js:129:7)
name: 'AlgoliaSearchError',
message: 'Invalid Application-ID or API key',
debugData:
[ { currentHost: 'https://ge24e6css9-dsn.algolia.net',
headers: [Object],
content: '{"params":"query=dav"}',
contentLength: 22,
method: 'POST',
timeouts: [Object],
url: '/1/indexes/INDEX/query',
startTime: 2017-01-13T17:46:42.519Z,
endTime: 2017-01-13T17:46:44.038Z,
duration: 1519,
statusCode: 403 } ],
statusCode: 403 } undefined
//-------------------------------------------------