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
This commit is contained in:
JJ Kasper 2022-01-27 16:58:01 -06:00 committed by GitHub
parent b314c9886c
commit 5ebc6d064f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 15 deletions

View file

@ -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}`)
})
})
```

View file

@ -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
<div class="card">