Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 92
fix(first-party): inject proxy endpoints for boolean/mock registry entries#640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
harlan-zw
merged 2 commits into
nuxt:main
from
oritwoen:fix/auto-inject-boolean-registryMar 13, 2026
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,178 @@ | ||
| import { describe, expect, it } from 'vitest' | ||
| import { autoInjectProxyEndpoints } from '../../src/first-party/auto-inject' | ||
| function makeRuntimeConfig(scripts: Record<string, any> = {}) { | ||
| return { public: { scripts } } | ||
| } | ||
| describe('autoInjectProxyEndpoints', () => { | ||
| describe('object entries', () => { | ||
| it('injects apiHost for posthog config object', () => { | ||
| const registry: any = { posthog: { apiKey: 'phc_test' } } | ||
| const rt = makeRuntimeConfig({ posthog: { apiKey: 'phc_test' } }) | ||
| autoInjectProxyEndpoints(registry, rt, '/_proxy') | ||
| expect(registry.posthog.apiHost).toBe('/_proxy/ph') | ||
| expect(rt.public.scripts.posthog.apiHost).toBe('/_proxy/ph') | ||
| }) | ||
| it('injects endpoint for plausible config object', () => { | ||
| const registry: any = { plausibleAnalytics: { domain: 'example.com' } } | ||
| const rt = makeRuntimeConfig({ plausibleAnalytics: { domain: 'example.com' } }) | ||
| autoInjectProxyEndpoints(registry, rt, '/_proxy') | ||
| expect(registry.plausibleAnalytics.endpoint).toBe('/_proxy/plausible/api/event') | ||
| expect(rt.public.scripts.plausibleAnalytics.endpoint).toBe('/_proxy/plausible/api/event') | ||
| }) | ||
| it('does not override existing config field', () => { | ||
| const registry: any = { posthog: { apiKey: 'phc_test', apiHost: 'https://custom.host' } } | ||
| const rt = makeRuntimeConfig({ posthog: { apiKey: 'phc_test', apiHost: 'https://custom.host' } }) | ||
| autoInjectProxyEndpoints(registry, rt, '/_proxy') | ||
| expect(registry.posthog.apiHost).toBe('https://custom.host') | ||
| expect(rt.public.scripts.posthog.apiHost).toBe('https://custom.host') | ||
| }) | ||
| it('uses EU prefix when posthog region is eu', () => { | ||
| const registry: any = { posthog: { apiKey: 'phc_test', region: 'eu' } } | ||
| const rt = makeRuntimeConfig({ posthog: { apiKey: 'phc_test', region: 'eu' } }) | ||
| autoInjectProxyEndpoints(registry, rt, '/_proxy') | ||
| expect(registry.posthog.apiHost).toBe('/_proxy/ph-eu') | ||
| }) | ||
| }) | ||
| describe('array entries', () => { | ||
| it('injects into first element of array entry', () => { | ||
| const registry: any = { posthog: [{ apiKey: 'phc_test' }, { partytown: true }] } | ||
| const rt = makeRuntimeConfig({ posthog: { apiKey: 'phc_test' } }) | ||
| autoInjectProxyEndpoints(registry, rt, '/_proxy') | ||
| expect(registry.posthog[0].apiHost).toBe('/_proxy/ph') | ||
| expect(rt.public.scripts.posthog.apiHost).toBe('/_proxy/ph') | ||
| }) | ||
| it('skips empty array entries', () => { | ||
| const registry: any = { posthog: [] } | ||
| const rt = makeRuntimeConfig({ posthog: { apiKey: '' } }) | ||
| autoInjectProxyEndpoints(registry, rt, '/_proxy') | ||
| expect(rt.public.scripts.posthog.apiHost).toBeUndefined() | ||
| }) | ||
| }) | ||
| describe('boolean entries', () => { | ||
| it('injects into runtimeConfig for posthog: true', () => { | ||
| const registry: any = { posthog: true } | ||
| const rt = makeRuntimeConfig({ posthog: { apiKey: '' } }) | ||
| autoInjectProxyEndpoints(registry, rt, '/_proxy') | ||
| expect(registry.posthog).toBe(true) | ||
| expect(rt.public.scripts.posthog.apiHost).toBe('/_proxy/ph') | ||
| }) | ||
| it('uses EU prefix for posthog: true when runtime region is eu', () => { | ||
| const registry: any = { posthog: true } | ||
| const rt = makeRuntimeConfig({ posthog: { apiKey: '', region: 'eu' } }) | ||
| autoInjectProxyEndpoints(registry, rt, '/_proxy') | ||
| expect(rt.public.scripts.posthog.apiHost).toBe('/_proxy/ph-eu') | ||
| }) | ||
| it('injects into runtimeConfig for plausibleAnalytics: true', () => { | ||
| const registry: any = { plausibleAnalytics: true } | ||
| const rt = makeRuntimeConfig({ plausibleAnalytics: { domain: '' } }) | ||
| autoInjectProxyEndpoints(registry, rt, '/_proxy') | ||
| expect(rt.public.scripts.plausibleAnalytics.endpoint).toBe('/_proxy/plausible/api/event') | ||
| }) | ||
| it('injects into runtimeConfig for umamiAnalytics: true', () => { | ||
| const registry: any = { umamiAnalytics: true } | ||
| const rt = makeRuntimeConfig({ umamiAnalytics: { websiteId: '' } }) | ||
| autoInjectProxyEndpoints(registry, rt, '/_proxy') | ||
| expect(rt.public.scripts.umamiAnalytics.hostUrl).toBe('/_proxy/umami') | ||
| }) | ||
| it('injects into runtimeConfig for rybbitAnalytics: true', () => { | ||
| const registry: any = { rybbitAnalytics: true } | ||
| const rt = makeRuntimeConfig({ rybbitAnalytics: { siteId: '' } }) | ||
| autoInjectProxyEndpoints(registry, rt, '/_proxy') | ||
| expect(rt.public.scripts.rybbitAnalytics.analyticsHost).toBe('/_proxy/rybbit/api') | ||
| }) | ||
| it('injects into runtimeConfig for databuddyAnalytics: true', () => { | ||
| const registry: any = { databuddyAnalytics: true } | ||
| const rt = makeRuntimeConfig({ databuddyAnalytics: { clientId: '' } }) | ||
| autoInjectProxyEndpoints(registry, rt, '/_proxy') | ||
| expect(rt.public.scripts.databuddyAnalytics.apiUrl).toBe('/_proxy/databuddy-api') | ||
| }) | ||
| }) | ||
| describe('mock entries', () => { | ||
| it('injects into runtimeConfig for posthog: mock', () => { | ||
| const registry: any = { posthog: 'mock' } | ||
| const rt = makeRuntimeConfig({ posthog: { apiKey: '' } }) | ||
| autoInjectProxyEndpoints(registry, rt, '/_proxy') | ||
| expect(rt.public.scripts.posthog.apiHost).toBe('/_proxy/ph') | ||
| }) | ||
| }) | ||
| describe('skipped entries', () => { | ||
| it('skips scripts not in AUTO_INJECT_DEFS', () => { | ||
| const registry: any = { googleAnalytics: { id: 'G-TEST' } } | ||
| const rt = makeRuntimeConfig({ googleAnalytics: { id: 'G-TEST' } }) | ||
| autoInjectProxyEndpoints(registry, rt, '/_proxy') | ||
| expect(rt.public.scripts.googleAnalytics).toEqual({ id: 'G-TEST' }) | ||
| }) | ||
| it('skips falsy entries', () => { | ||
| const registry: any = { posthog: false } | ||
| const rt = makeRuntimeConfig() | ||
| autoInjectProxyEndpoints(registry, rt, '/_proxy') | ||
| expect(rt.public.scripts.posthog).toBeUndefined() | ||
| }) | ||
| it('does not modify existing runtimeConfig for falsy entry', () => { | ||
| const registry: any = { posthog: false } | ||
| const rt = makeRuntimeConfig({ posthog: { existing: 'value' } }) | ||
| autoInjectProxyEndpoints(registry, rt, '/_proxy') | ||
| expect(rt.public.scripts.posthog).toEqual({ existing: 'value' }) | ||
| }) | ||
| }) | ||
| describe('custom collectPrefix', () => { | ||
| it('uses custom prefix in computed values', () => { | ||
| const registry: any = { posthog: true } | ||
| const rt = makeRuntimeConfig({ posthog: { apiKey: '' } }) | ||
| autoInjectProxyEndpoints(registry, rt, '/_analytics') | ||
| expect(rt.public.scripts.posthog.apiHost).toBe('/_analytics/ph') | ||
| }) | ||
| }) | ||
| }) |
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.