Skip to content

Commit

Permalink
Move custom server note from middleware doc (vercel#33744)
Browse files Browse the repository at this point in the history
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: vercel#33535 (comment)
  • Loading branch information
ijjk authored and natew committed Feb 16, 2022
1 parent a603cc7 commit 8a6a186
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
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

0 comments on commit 8a6a186

Please sign in to comment.