Vercel Edge
Vercel Edge middleware allows you to intercept the requests to your application served by Vercel platform. We will create a simple Next.js application and send the traffic events to Upstash Kafka using the Vercel Edge functions.
Create a Next.js application:
Create a middleware.ts (or .js) file in your app directory. Update the file as below:
Above, we simply parse the request object and send useful information to Kafka. You may add/remove information depending on your own requirements.
Configure Credentials
We’re going to store our credentials in .env
file. You can copy/paste the necessary credentials from the Upstash Console.
You can test the function locally with npm run dev
. Deploy your function to
Vercel with vercel --prod
The endpoint of the function will be printed. You can check if logs are
collected in Kafka by copying the curl
expression from the console:
Conclusion
We have successfully built to the pipeline to collect the traffic data from our web application to Upstash Kafka. In the remaining of the series, we will analyze the data in Kafka with different realtime analytics tool which are capable to read from Kafka.
Was this page helpful?