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
-
Install the package:
-
Set the key from the setup screen as
WANIWANI_AGENT_TRAFFIC_KEYon the server that runs the app in production. For example, put it in.env.productionor in the configuration of the service. Then restart the app.
Create proxy.ts
Createproxy.ts next to your app or pages folder:
proxy.ts
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 thisproxy.ts. It also calls serveAgentPage:
proxy.ts
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
afterkeeps 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.