Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move custom server note from middleware doc #33744

Merged
merged 7 commits into from Jan 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions docs/advanced-features/custom-server.md
Expand Up @@ -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(() => {
Expand All @@ -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}`)
})
})
```
Expand Down
12 changes: 0 additions & 12 deletions docs/middleware.md
Expand Up @@ -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">
Expand Down