Skip to content

Commit f4c1594

Browse files
saevarbijjk
andauthored
Update middleware documentation for custom server (#33535)
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. Fixes #33450 which seems to have been erroneously closed. ## Bug - [X] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `yarn lint` Co-authored-by: JJ Kasper <[email protected]>
1 parent ebe95f4 commit f4c1594

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

docs/middleware.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ 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+
7991
## Related
8092

8193
<div class="card">

0 commit comments

Comments
 (0)