Skip to content

Commit a901469

Browse files
committed
fix(vercel-analytics): sink insight POSTs in dev to avoid 404s
Vercel Analytics collects via a relative `/_vercel/insights/*` endpoint served by Vercel's edge. Outside Vercel (including `nuxt dev`) there is no upstream, so the script POSTs to the local origin and 404s. Register a dev-only handler that returns 204 on that path when vercelAnalytics is enabled. Script behaviour, options (mode/debug), and proxy domains are unchanged.
1 parent f4a4df6 commit a901469

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

packages/script/src/module.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,16 @@ export default defineNuxtModule<ModuleOptions>({
527527
const proxyHandlerPath = await resolvePath('./runtime/server/proxy-handler')
528528
addServerHandler({ route: `${proxyPrefix}/**`, handler: proxyHandlerPath })
529529

530+
// In dev, sink Vercel Analytics insight POSTs to `/_vercel/insights/*` so
531+
// they don't 404. Vercel's edge serves this path in production; locally
532+
// there's no upstream, so we return 204 to keep the script happy.
533+
if (nuxt.options.dev && config.registry?.vercelAnalytics) {
534+
addServerHandler({
535+
route: '/_vercel/insights/**',
536+
handler: await resolvePath('./runtime/server/vercel-insights-sink'),
537+
})
538+
}
539+
530540
const composables = [
531541
'useScript',
532542
'useScriptEventPage',
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { defineEventHandler, setResponseStatus } from 'h3'
2+
3+
export default defineEventHandler((event) => {
4+
setResponseStatus(event, 204)
5+
return null
6+
})

0 commit comments

Comments
 (0)