Skip to content

Commit 8ef0d39

Browse files
authored
fix(vercel-analytics): skip script in dev to avoid failed insights POSTs (#713)
1 parent a660032 commit 8ef0d39

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
@@ -573,6 +573,16 @@ export default defineNuxtModule<ModuleOptions>({
573573
const proxyHandlerPath = await resolvePath('./runtime/server/proxy-handler')
574574
addServerHandler({ route: `${proxyPrefix}/**`, handler: proxyHandlerPath })
575575

576+
// In dev, sink Vercel Analytics insight POSTs to `/_vercel/insights/*` so
577+
// they don't 404. Vercel's edge serves this path in production; locally
578+
// there's no upstream, so we return 204 to keep the script happy.
579+
if (nuxt.options.dev && config.registry?.vercelAnalytics) {
580+
addServerHandler({
581+
route: '/_vercel/insights/**',
582+
handler: await resolvePath('./runtime/server/vercel-insights-sink'),
583+
})
584+
}
585+
576586
const composables = [
577587
'useScript',
578588
'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)