From 5ebc6d064f8d3b0ad44c4576bbdfff6c1d3adbc4 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Thu, 27 Jan 2022 16:58:01 -0600 Subject: [PATCH] Move custom server note from middleware doc (#33744) This moves the note about custom server handling for middleware to the custom server document. ## Documentation / Examples - [x] Make sure the linting passes by running `yarn lint` x-ref: https://github.com/vercel/next.js/pull/33535#discussion_r790110427 --- docs/advanced-features/custom-server.md | 9 ++++++--- docs/middleware.md | 12 ------------ 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/docs/advanced-features/custom-server.md b/docs/advanced-features/custom-server.md index d476b52c08edc..d887c841025c1 100644 --- a/docs/advanced-features/custom-server.md +++ b/docs/advanced-features/custom-server.md @@ -29,7 +29,10 @@ const { parse } = require('url') const next = require('next') const dev = process.env.NODE_ENV !== 'production' -const app = next({ dev }) +const hostname = 'localhost' +const port = 3000 +// when using middleware `hostname` and `port` must be provided below +const app = next({ dev, hostname, port }) const handle = app.getRequestHandler() app.prepare().then(() => { @@ -46,9 +49,9 @@ app.prepare().then(() => { } else { handle(req, res, parsedUrl) } - }).listen(3000, (err) => { + }).listen(port, (err) => { if (err) throw err - console.log('> Ready on http://localhost:3000') + console.log(`> Ready on http://${hostname}:${port}`) }) }) ``` diff --git a/docs/middleware.md b/docs/middleware.md index a660afd0f81c3..327f61179675e 100644 --- a/docs/middleware.md +++ b/docs/middleware.md @@ -76,18 +76,6 @@ 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