#Middleware without edge?
1 messages · Page 1 of 1 (latest)
Yes, you are correct. Middleware in Next.js does not require running "at the edge" and can work in a single-region server. This means that you can use Middleware without an edge network. However, if you want to run Middleware in multiple regions, additional configuration and infrastructure are required.
It's important to note that Middleware uses a runtime that is a subset of all available Node.js APIs to ensure low latency. This runtime is referred to as the "Edge runtime". Despite its name, it doesn't imply that it must be run on an edge network. The term "Edge" in this context refers to the fact that this runtime is designed to be lightweight and fast, making it suitable for edge computing scenarios, but it's not a requirement.
If you need to use all Node.js APIs or certain npm packages that are not supported by the Edge runtime, you might need to move your logic to a layout as a Server Component, use next.config.js for redirects or rewrites, or use a custom server.
Please refer to the following sources for more information:
- Middleware (https://nextjs.org/docs/app/building-your-application/routing/middleware)
- Edge and Node.js Runtimes (https://nextjs.org/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
- Server Components (https://nextjs.org/docs/app/building-your-application/rendering/server-components)
- Custom Server (https://nextjs.org/docs/pages/building-your-application/configuring/custom-server)