From d4f081ad2a43058bc35c166b62283c8057fd9cc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A6var=20Berg?= Date: Fri, 21 Jan 2022 13:21:14 +0100 Subject: [PATCH 1/3] Update middleware documentation for custom server Upgrading from 12.0.0 to 12.0.8 results in `[dev] error - Error: To use middleware you must provide a `hostname` and `port` to the Next.js Server` and this requirement did not seem to be documented anywhere. --- docs/middleware.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docs/middleware.md b/docs/middleware.md index 327f61179675e..b149b29fd53d7 100644 --- a/docs/middleware.md +++ b/docs/middleware.md @@ -76,6 +76,19 @@ Middleware runs directly after `redirects` and `headers`, before the first files Middleware uses a [strict runtime](/docs/api-reference/edge-runtime.md) that supports standard Web APIs like `fetch`. This works out of the box using `next start`, as well as on Edge platforms like Vercel, which use [Edge Functions](http://www.vercel.com/edge). +## Custom server + +When using a custom server with middleware, you must specify the hostname and port when instantiating your `NextApp`. + +```ts +import next from "next"; +// ... +const port = process.env.PORT ? +process.env.PORT : 3000; +const dev = process.env.NODE_ENV !== "production"; +const app = next({ dev, customServer: true, hostname: "localhost", port }); +``` + + ## Related
From 16fc45e31a872f34d2970b1f18274e4b3e6ef4a0 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Fri, 21 Jan 2022 14:58:24 -0600 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Steven --- docs/middleware.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/middleware.md b/docs/middleware.md index b149b29fd53d7..5b53f3069582c 100644 --- a/docs/middleware.md +++ b/docs/middleware.md @@ -76,7 +76,7 @@ Middleware runs directly after `redirects` and `headers`, before the first files Middleware uses a [strict runtime](/docs/api-reference/edge-runtime.md) that supports standard Web APIs like `fetch`. This works out of the box using `next start`, as well as on Edge platforms like Vercel, which use [Edge Functions](http://www.vercel.com/edge). -## Custom server +## Custom Server When using a custom server with middleware, you must specify the hostname and port when instantiating your `NextApp`. From 0de75bbf4b3032bf1db134d82607f28be9dc041e Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Fri, 21 Jan 2022 15:12:14 -0600 Subject: [PATCH 3/3] lint-fix --- docs/middleware.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/docs/middleware.md b/docs/middleware.md index 5b53f3069582c..a660afd0f81c3 100644 --- a/docs/middleware.md +++ b/docs/middleware.md @@ -81,14 +81,13 @@ Middleware uses a [strict runtime](/docs/api-reference/edge-runtime.md) that sup When using a custom server with middleware, you must specify the hostname and port when instantiating your `NextApp`. ```ts -import next from "next"; +import next from 'next' // ... -const port = process.env.PORT ? +process.env.PORT : 3000; -const dev = process.env.NODE_ENV !== "production"; -const app = next({ dev, customServer: true, hostname: "localhost", port }); +const port = process.env.PORT ? +process.env.PORT : 3000 +const dev = process.env.NODE_ENV !== 'production' +const app = next({ dev, customServer: true, hostname: 'localhost', port }) ``` - ## Related