File tree Expand file tree Collapse file tree 2 files changed +15
-4
lines changed
Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -7,14 +7,17 @@ import {
77
88/**
99 * Algolia search client for npm packages.
10- * Uses npm's public Algolia index (same as npmjs.com) .
10+ * Credentials and index name come from runtimeConfig.public.algolia .
1111 */
1212let _searchClient : LiteClient | null = null
13+ let _configuredAppId : string | null = null
1314
1415function getAlgoliaClient ( ) : LiteClient {
15- if ( ! _searchClient ) {
16- // npm's public search-only Algolia credentials (same as npmjs.com uses)
17- _searchClient = algoliasearch ( 'OFCNCOG2CU' , 'f54e21fa3a2a0160595bb058179bfb1e' )
16+ const { algolia } = useRuntimeConfig ( ) . public
17+ // Re-create client if app ID changed (shouldn't happen, but be safe)
18+ if ( ! _searchClient || _configuredAppId !== algolia . appId ) {
19+ _searchClient = algoliasearch ( algolia . appId , algolia . apiKey )
20+ _configuredAppId = algolia . appId
1821 }
1922 return _searchClient
2023}
Original file line number Diff line number Diff line change @@ -33,6 +33,14 @@ export default defineNuxtConfig({
3333 redisRestUrl : process . env . UPSTASH_KV_REST_API_URL || process . env . KV_REST_API_URL || '' ,
3434 redisRestToken : process . env . UPSTASH_KV_REST_API_TOKEN || process . env . KV_REST_API_TOKEN || '' ,
3535 } ,
36+ public : {
37+ // Algolia npm-search index (maintained by Algolia & jsDelivr, used by yarnpkg.com et al.)
38+ algolia : {
39+ appId : 'OFCNCOG2CU' ,
40+ apiKey : 'f54e21fa3a2a0160595bb058179bfb1e' ,
41+ indexName : 'npm-search' ,
42+ } ,
43+ } ,
3644 } ,
3745
3846 devtools : { enabled : true } ,
You can’t perform that action at this time.
0 commit comments