Company
Date Published
Author
Salma Alam-Naylor
Word count
1726
Language
English
Hacker News points
None

Summary

Next.js Advanced Middleware allows developers to intercept and rewrite the response of a Next.js statically generated page at the edge based on geolocation data, transforming page props on the fly. With Netlify Edge Functions, this middleware can run code before an HTTP request is completed, modifying the HTTP response before it's returned. The middleware can be used to personalize pages with location-specific content, and can also update page props using `setPageProp`. The process involves creating a new Next.js project, adding a static route, and writing middleware code in TypeScript that uses Netlify Edge Functions to rewrite the HTML response. The demo site is deployed to Netlify, where the changes can be seen in real-time on a live URL.