Unverified Commit 5ebc6d06 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

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
parent b314c988
...@@ -29,7 +29,10 @@ const { parse } = require('url') ...@@ -29,7 +29,10 @@ const { parse } = require('url')
const next = require('next') const next = require('next')
const dev = process.env.NODE_ENV !== 'production' 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() const handle = app.getRequestHandler()
app.prepare().then(() => { app.prepare().then(() => {
...@@ -46,9 +49,9 @@ app.prepare().then(() => { ...@@ -46,9 +49,9 @@ app.prepare().then(() => {
} else { } else {
handle(req, res, parsedUrl) handle(req, res, parsedUrl)
} }
}).listen(3000, (err) => { }).listen(port, (err) => {
if (err) throw err if (err) throw err
console.log('> Ready on http://localhost:3000') console.log(`> Ready on http://${hostname}:${port}`)
}) })
}) })
``` ```
......
...@@ -76,18 +76,6 @@ Middleware runs directly after `redirects` and `headers`, before the first files ...@@ -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). 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 ## Related
<div class="card"> <div class="card">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment