Skip to content

Commit 5fc6b7d

Browse files
committedSep 26, 2024
feat: allow fallbackToApi to be set to server-only or client-only
1 parent cc14fe4 commit 5fc6b7d

File tree

5 files changed

+11
-4
lines changed

5 files changed

+11
-4
lines changed
 

‎playground/nuxt.config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export default defineNuxtConfig({
2323
},
2424
],
2525
serverBundle: 'remote',
26+
fallbackToApi: 'server-only',
2627
// serverBundle: {
2728
// externalizeIconsJson: true,
2829
// },

‎src/runtime/plugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default defineNuxtPlugin({
2020
const baseURL = config.app?.baseURL?.replace(/\/$/, '') ?? ''
2121

2222
resources.push(baseURL + (options.localApiEndpoint || '/api/_nuxt_icon'))
23-
if (options.fallbackToApi) {
23+
if (options.fallbackToApi === true || options.fallbackToApi === 'client-only') {
2424
resources.push(options.iconifyApiEndpoint!)
2525
}
2626
}

‎src/runtime/server/api.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export default defineCachedEventHandler(async (event: H3Event) => {
4747
}
4848
}
4949

50-
if (options.fallbackToApi) {
50+
if (options.fallbackToApi === true || options.fallbackToApi === 'server-only') {
5151
consola.debug(`[Icon] fetching ${(icons || []).map(i => '`' + collectionName + ':' + i + '`').join(',')} from iconify api`)
5252
if (apiUrl.host !== new URL(apiEndPoint).host) {
5353
return createError({ status: 400, message: 'Invalid icon request' })

‎src/schema-types.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export interface NuxtIconRuntimeOptions {
9999
*
100100
* @enum server,iconify
101101
*/
102-
provider: string | undefined
102+
provider: 'server' | 'iconify' | undefined
103103

104104
/**
105105
* Iconify API Endpoint URL
@@ -116,8 +116,10 @@ export interface NuxtIconRuntimeOptions {
116116
* Fallback to Iconify API if server provider fails to found the collection.
117117
*
118118
* @default true
119+
*
120+
* @enum true,false,server-only,client-only
119121
*/
120-
fallbackToApi: boolean
122+
fallbackToApi: boolean | 'server-only' | 'client-only'
121123

122124
/**
123125
* Local API Endpoint Path

‎src/schema.ts

+4
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ export const schema = {
109109
].join('\n'),
110110
enum: ['server', 'iconify'],
111111
tags: ['@studioIcon material-symbols:cloud'],
112+
type: '"server" | "iconify" | undefined',
112113
},
113114
},
114115
iconifyApiEndpoint: {
@@ -125,6 +126,8 @@ export const schema = {
125126
title: 'Fallback to Iconify API',
126127
description: 'Fallback to Iconify API if server provider fails to found the collection.',
127128
tags: ['@studioIcon material-symbols:public'],
129+
enum: [true, false, 'server-only', 'client-only'],
130+
type: 'boolean | "server-only" | "client-only"',
128131
},
129132
},
130133
localApiEndpoint: {
@@ -149,6 +152,7 @@ export const schema = {
149152
title: 'Customize callback',
150153
description: 'Customize icon content (replace stroke-width, colors, etc...).',
151154
tags: ['@studioIcon material-symbols:edit'],
155+
type: 'IconifyIconCustomizeCallback',
152156
},
153157
},
154158
} satisfies SchemaDefinition

0 commit comments

Comments
 (0)
Please sign in to comment.