Skip to main content
Use this setup when your Next.js app runs on your own server, and no CDN that Waniwani supports serves the HTML. An example is next start on AWS EC2. The relay is a proxy.ts file. Next.js runs it as its proxy. You need Next.js 16 or later. The code on this page is for the US region with Every page selected. Copy your code from the setup screen. It has your region and your paths.

Before you start

  1. Install the package:
  2. Set the key from the setup screen as WANIWANI_AGENT_TRAFFIC_KEY on the server that runs the app in production. For example, put it in .env.production or in the configuration of the service. Then restart the app.

Create proxy.ts

Create proxy.ts next to your app or pages folder:
proxy.ts
If the project already has a proxy.ts or a middleware.ts, add the if block at the top of its function.

With agent pages or blocking

When the website serves agent pages or blocks an agent, the setup screen gives you this proxy.ts. It also calls serveAgentPage:
proxy.ts
You make this change one time. After it, you turn agent pages and blocking on and off in the dashboard, with no deploy.

Deploy and check

Build and deploy to production. In the setup screen, enter the address of one of your pages and click Check now.

Notes

  • after keeps the request open until the event goes to Waniwani. The agent does not wait for the event. This is important when the server can stop or freeze after the response.
  • The relay does not know this platform. Thus, the website keeps the platform that you selected in the setup.
  • With Only some paths, the matcher has your paths. /blog/* becomes /blog/:path*. Also add the paths of your agent pages.
  • In the EU region, each call gets region: "eu".
  • To open this setup directly, use https://app.waniwani.ai/agent-traffic/websites/new?platform=self-hosted.