From e65e737bee361094349884fab4596926ad9c951b Mon Sep 17 00:00:00 2001 From: Tom Bernens Date: Fri, 15 May 2026 18:06:41 -0700 Subject: [PATCH] user-agent.ts defines global user-agent string for all http requests instrumentation.ts sets axios default user-agent to our global user-agent string on library import --- src/instrumentation.ts | 7 +++++++ src/lib/utils/user-agent.ts | 3 +++ 2 files changed, 10 insertions(+) create mode 100644 src/instrumentation.ts create mode 100644 src/lib/utils/user-agent.ts diff --git a/src/instrumentation.ts b/src/instrumentation.ts new file mode 100644 index 0000000..2beabfa --- /dev/null +++ b/src/instrumentation.ts @@ -0,0 +1,7 @@ +export async function register() { + if (process.env.NEXT_RUNTIME === 'nodejs') { + const axios = (await import('axios')).default; + const { RMAB_USER_AGENT } = await import('@/lib/utils/user-agent'); + axios.defaults.headers.common['User-Agent'] = RMAB_USER_AGENT; + } +} diff --git a/src/lib/utils/user-agent.ts b/src/lib/utils/user-agent.ts new file mode 100644 index 0000000..b2876d2 --- /dev/null +++ b/src/lib/utils/user-agent.ts @@ -0,0 +1,3 @@ +import { version } from '../../../package.json'; + +export const RMAB_USER_AGENT = `rmab/${version}`;