Skip to content

Commit 598d438

Browse files
authored
fix: register server handler only for server provider (#524)
1 parent e062607 commit 598d438

3 files changed

Lines changed: 35 additions & 4 deletions

File tree

src/module.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,12 @@ export default defineNuxtModule<ModuleOptions>({
9292
global: true,
9393
filePath: await resolver.resolvePath('./runtime/components/index'),
9494
})
95-
addServerHandler({
96-
route: `${options.localApiEndpoint || '/api/_nuxt_icon'}/:collection`,
97-
handler: resolver.resolve('./runtime/server/api'),
98-
})
95+
if (options.provider === 'server') {
96+
addServerHandler({
97+
route: `${options.localApiEndpoint || '/api/_nuxt_icon'}/:collection`,
98+
handler: resolver.resolve('./runtime/server/api'),
99+
})
100+
}
99101

100102
await setupCustomCollectionsWatcher(options, nuxt, ctx)
101103

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import NuxtIcon from '../../../src/module'
2+
3+
export default defineNuxtConfig({
4+
modules: [
5+
[NuxtIcon, {
6+
provider: 'iconify',
7+
serverBundle: false,
8+
}],
9+
],
10+
})

test/module.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { fileURLToPath } from 'node:url'
2+
import { describe, expect, it } from 'vitest'
3+
import { setup, useTestContext } from '@nuxt/test-utils/e2e'
4+
5+
describe('module', async () => {
6+
await setup({
7+
rootDir: fileURLToPath(new URL('./fixtures/iconify-provider', import.meta.url)),
8+
build: true,
9+
server: false,
10+
})
11+
12+
it('does not register the local API handler for the iconify provider', () => {
13+
const handlers = useTestContext().nuxt?.options.serverHandlers
14+
15+
expect(handlers).not.toContainEqual(expect.objectContaining({
16+
route: '/api/_nuxt_icon/:collection',
17+
}))
18+
})
19+
})

0 commit comments

Comments
 (0)