Skip to content

Commit 5ebc6d0

Browse files
authored
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: #33535 (comment)
1 parent b314c98 commit 5ebc6d0

2 files changed

Lines changed: 6 additions & 15 deletions

File tree

docs/advanced-features/custom-server.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ const { parse } = require('url')
2929
const next = require('next')
3030

3131
const dev = process.env.NODE_ENV !== 'production'
32-
const app = next({ dev })
32+
const hostname = 'localhost'
33+
const port = 3000
34+
// when using middleware `hostname` and `port` must be provided below
35+
const app = next({ dev, hostname, port })
3336
const handle = app.getRequestHandler()
3437

3538
app.prepare().then(() => {
@@ -46,9 +49,9 @@ app.prepare().then(() => {
4649
} else {
4750
handle(req, res, parsedUrl)
4851
}
49-
}).listen(3000, (err) => {
52+
}).listen(port, (err) => {
5053
if (err) throw err
51-
console.log('> Ready on http://localhost:3000')
54+
console.log(`> Ready on http://${hostname}:${port}`)
5255
})
5356
})
5457
```

docs/middleware.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,6 @@ Middleware runs directly after `redirects` and `headers`, before the first files
7676

7777
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).
7878

79-
## Custom Server
80-
81-
When using a custom server with middleware, you must specify the hostname and port when instantiating your `NextApp`.
82-
83-
```ts
84-
import next from 'next'
85-
// ...
86-
const port = process.env.PORT ? +process.env.PORT : 3000
87-
const dev = process.env.NODE_ENV !== 'production'
88-
const app = next({ dev, customServer: true, hostname: 'localhost', port })
89-
```
90-
9179
## Related
9280

9381
<div class="card">

0 commit comments

Comments
 (0)