Skip to content

Commit 192ef68

Browse files
committed
refactor: extract creds to runtime config
1 parent 4f6c2df commit 192ef68

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

app/composables/npm/useAlgoliaSearch.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff 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
*/
1212
let _searchClient: LiteClient | null = null
13+
let _configuredAppId: string | null = null
1314

1415
function 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
}

nuxt.config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff 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 },

0 commit comments

Comments
 (0)