Nuxt 3 is powered by Nitro, a server engine that exposes routeRules for edge-level request manipulation. With two lines in nuxt.config.ts you can proxy /js/script.js and /api/event to Admaxxer without writing a custom server route.
admaxxer.com will not block your own domain.SameSite cookies work correctly for session tracking.routeRules proxies run at the CDN edge with no origin round-trip.nuxt.config.ts.// nuxt.config.ts
export default defineNuxtConfig({
routeRules: {
'/js/script.js': {
proxy: 'https://admaxxer.com/js/script.js',
},
'/api/event/**': {
proxy: 'https://admaxxer.com/api/event/**',
},
},
});
The ** glob forwards any sub-path and query string. This is important for the event endpoint which may receive path segments like /api/event/batch.
In development:
npm run dev
Nuxt hot-reloads most config changes; a full restart is safest after touching routeRules. In production, trigger a new build and deployment:
npm run build && npm run preview # local preview
# or push to your deployment provider
In Admaxxer go to Connections › Install, enable Custom proxy domain, and enter your site's domain. Copy the new snippet and replace the old one in your app.vue or layout head.
For Nuxt, use useHead in your app layout:
// app.vue or layouts/default.vue
useHead({
script: [
{
src: '/js/script.js',
defer: true,
'data-api': '/api/event',
'data-domain': 'yourdomain.com',
},
],
});
curl -I https://yourdomain.com/js/script.js
# Expect: HTTP/2 200 content-type: application/javascript
curl -X POST https://yourdomain.com/api/event \
-H 'Content-Type: application/json' \
-d '{"name":"pageview","url":"https://yourdomain.com/"}'
# Expect: HTTP/2 200 or 204
Nuxt 2 uses a different server engine (h3/connect). Use the server middleware approach instead:
// server/middleware/admaxxer-proxy.ts (Nuxt 2 with Bridge)
import { createProxyMiddleware } from 'http-proxy-middleware';
const proxy = createProxyMiddleware({
target: 'https://admaxxer.com',
changeOrigin: true,
pathFilter: ['/js/script.js', '/api/event'],
});
export default proxy;
Install http-proxy-middleware (npm install http-proxy-middleware) and add this file. Nuxt 2 server middleware runs for every matched path.
routeRules is not supported — use the middleware approach above.admaxxer.com from the server environment. This can happen in some locked-down cloud environments — check outbound egress rules.ssr: false) disable server-side route rules. Ensure your Nuxt preset supports server-side rendering or edge functions.Remove the two routeRules entries and redeploy. Disable the custom proxy domain in Admaxxer to revert the snippet to point at admaxxer.com.
Cloudflare · Vercel · Next.js · Netlify · WordPress · Apache · NGINX
See also: Connections › Install for the base snippet.