From 1b9de127aed331671b14859a2ef6efdbd9ef1483 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esben=20Anker-M=C3=B8ller?= <3149747+esbenam@users.noreply.github.com> Date: Thu, 25 Aug 2022 08:34:30 +0200 Subject: [PATCH] Adds note about custom server requirements This wasn't obvious to me when trying out middleware in our project, and the error message was `Invalid URL` - took me embarrassingly long to remember that we run a custom server. Would it be possibly to detect that middleware is used and then throw a descriptive error message when trying to call `next` without `hostname` and `port` in a custom server? If someone can point me to where that could be done, I would be happy to make a pull request. --- docs/advanced-features/middleware.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/advanced-features/middleware.md b/docs/advanced-features/middleware.md index 74454c5470b5..2dbd2f290eb7 100644 --- a/docs/advanced-features/middleware.md +++ b/docs/advanced-features/middleware.md @@ -21,6 +21,8 @@ Middleware runs _before_ cached content, so you can personalize static files and > **Note:** If you were using Middleware prior to `12.2`, please see the [upgrade guide](https://nextjs.org/docs/messages/middleware-upgrade-guide). +> **Note:** If you are using a [custom server](https://nextjs.org/docs/advanced-features/custom-server) you must provide `hostname` and `port` when calling `next` i.e `next({ hostname: 'localhost', port: 3000 })`. + ## Using Middleware To begin using Middleware, follow the steps below: