Proxy Admaxxer Through Next.js Rewrites

Next.js has a built-in rewrites feature in next.config.js that transparently forwards requests to an external URL while keeping your domain in the browser's address bar. This makes it the cleanest way to proxy the Admaxxer pixel in a Next.js project — no API routes, no middleware files, no extra dependencies.

Why Use next.config.js Rewrites?

Prerequisites

Step 1 — Add Rewrites to next.config.js

Open next.config.js (or next.config.mjs) and add an async rewrites function:

/** @type {import('next').NextConfig} */
const nextConfig = {
  async rewrites() {
    return [
      {
        source: '/js/script.js',
        destination: 'https://admaxxer.com/js/script.js',
      },
      {
        source: '/api/event/:path*',
        destination: 'https://admaxxer.com/api/event/:path*',
      },
    ];
  },
};

module.exports = nextConfig;

If you use ES modules (next.config.mjs):

/** @type {import('next').NextConfig} */
const nextConfig = {
  async rewrites() {
    return [
      {
        source: '/js/script.js',
        destination: 'https://admaxxer.com/js/script.js',
      },
      {
        source: '/api/event/:path*',
        destination: 'https://admaxxer.com/api/event/:path*',
      },
    ];
  },
};

export default nextConfig;

Step 2 — Restart the Dev Server

Rewrites are read at startup. Stop your dev server and restart it:

npm run dev

For production, redeploy. On Vercel a git push triggers a new deployment automatically.

Step 3 — Update Admaxxer Snippet

In Admaxxer go to Connections › Install, enable Custom proxy domain, and enter your domain. The updated snippet will load /js/script.js and post to /api/event on your own domain.

Step 4 — Test

# Script loads
curl -I https://yourdomain.com/js/script.js

# Event endpoint accepts POST
curl -X POST https://yourdomain.com/api/event \
  -H 'Content-Type: application/json' \
  -d '{"name":"test","url":"https://yourdomain.com/test"}'

The script request should return 200 application/javascript. The event POST should return 200 or 204.

App Router Middleware Alternative

If you need to add custom logic (e.g., injecting a workspace header) you can use Next.js Middleware instead:

// middleware.ts
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';

export function middleware(request: NextRequest) {
  const url = request.nextUrl;
  if (
    url.pathname === '/js/script.js' ||
    url.pathname.startsWith('/api/event')
  ) {
    const target = new URL(
      url.pathname + url.search,
      'https://admaxxer.com'
    );
    return NextResponse.rewrite(target);
  }
}

export const config = {
  matcher: ['/js/script.js', '/api/event/:path*'],
};

The next.config.js approach is simpler and preferred unless you need per-request logic.

Troubleshooting

Rollback

Remove the two rewrite entries from next.config.js and restart (or redeploy). Disable the custom proxy domain in Admaxxer to revert the snippet.

Other Proxy Guides

Cloudflare · Vercel · Nuxt · Netlify · WordPress · Apache · NGINX

See also: Connections › Install for the base snippet.