Proxy Admaxxer Through Nuxt (Nitro Route Rules)

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.

Why Proxy?

Prerequisites

Step 1 — Add routeRules to 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.

Step 2 — Restart or Redeploy

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

Step 3 — Update the Admaxxer Snippet

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',
    },
  ],
});

Step 4 — Test

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 / Nuxt Bridge

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.

Troubleshooting

Rollback

Remove the two routeRules entries and redeploy. Disable the custom proxy domain in Admaxxer to revert the snippet to point at admaxxer.com.

Other Proxy Guides

Cloudflare · Vercel · Next.js · Netlify · WordPress · Apache · NGINX

See also: Connections › Install for the base snippet.