Skip to content

Commit

Permalink
Move custom server note from middleware doc (#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: #33535 (comment)
  • Loading branch information
ijjk committed Jan 27, 2022
1 parent b314c98 commit 5ebc6d0
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

1 comment on commit 5ebc6d0

@ijjk
Copy link
Member Author

@ijjk ijjk commented on 5ebc6d0 Jan 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stats from current release

Default Build (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js canary v12.0.9 vercel/next.js refs/heads/canary Change
buildDuration 14.4s 14.4s -71ms
buildDurationCached 3.6s 4.1s ⚠️ +496ms
nodeModulesSize 358 MB 358 MB ⚠️ +4.76 kB
Page Load Tests Overall decrease ⚠️
vercel/next.js canary v12.0.9 vercel/next.js refs/heads/canary Change
/ failed reqs 0 0
/ total time (seconds) 3.381 3.34 -0.04
/ avg req/sec 739.32 748.55 +9.23
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 1.541 1.576 ⚠️ +0.04
/error-in-render avg req/sec 1621.88 1586.54 ⚠️ -35.34
Client Bundles (main, webpack, commons) Overall increase ⚠️
vercel/next.js canary v12.0.9 vercel/next.js refs/heads/canary Change
450.HASH.js gzip 179 B 179 B
framework-HASH.js gzip 42.2 kB 42.2 kB
main-HASH.js gzip 27.2 kB 27.2 kB ⚠️ +18 B
webpack-HASH.js gzip 1.44 kB 1.44 kB
Overall change 71 kB 71 kB ⚠️ +18 B
Legacy Client Bundles (polyfills)
vercel/next.js canary v12.0.9 vercel/next.js refs/heads/canary Change
polyfills-HASH.js gzip 31 kB 31 kB
Overall change 31 kB 31 kB
Client Pages
vercel/next.js canary v12.0.9 vercel/next.js refs/heads/canary Change
_app-HASH.js gzip 1.37 kB 1.37 kB
_error-HASH.js gzip 194 B 194 B
amp-HASH.js gzip 312 B 312 B
css-HASH.js gzip 326 B 326 B
dynamic-HASH.js gzip 2.37 kB 2.37 kB
head-HASH.js gzip 350 B 350 B
hooks-HASH.js gzip 919 B 919 B
image-HASH.js gzip 4.94 kB 4.94 kB
index-HASH.js gzip 263 B 263 B
link-HASH.js gzip 2.19 kB 2.19 kB
routerDirect..HASH.js gzip 321 B 321 B
script-HASH.js gzip 383 B 383 B
withRouter-HASH.js gzip 318 B 318 B
85e02e95b279..7e3.css gzip 107 B 107 B
Overall change 14.4 kB 14.4 kB
Client Build Manifests
vercel/next.js canary v12.0.9 vercel/next.js refs/heads/canary Change
_buildManifest.js gzip 460 B 460 B
Overall change 460 B 460 B
Rendered Page Sizes Overall decrease ✓
vercel/next.js canary v12.0.9 vercel/next.js refs/heads/canary Change
index.html gzip 531 B 530 B -1 B
link.html gzip 545 B 545 B
withRouter.html gzip 526 B 525 B -1 B
Overall change 1.6 kB 1.6 kB -2 B

Diffs

Diff for main-HASH.js
@@ -628,7 +628,7 @@
         document.getElementById("__NEXT_DATA__").textContent
       );
       window.__NEXT_DATA__ = data;
-      var version = "12.0.9";
+      var version = "12.0.10-canary.0";
       exports.version = version;
       var looseToArray = function(input) {
         return [].slice.call(input);
@@ -3876,6 +3876,28 @@
       /***/
     },
 
+    /***/ 8887: /***/ function(__unused_webpack_module, exports) {
+      "use strict";
+
+      Object.defineProperty(exports, "__esModule", {
+        value: true
+      });
+      exports.getObjectClassLabel = getObjectClassLabel;
+      exports.isPlainObject = isPlainObject;
+      function getObjectClassLabel(value) {
+        return Object.prototype.toString.call(value);
+      }
+      function isPlainObject(value) {
+        if (getObjectClassLabel(value) !== "[object Object]") {
+          return false;
+        }
+        var prototype = Object.getPrototypeOf(value);
+        return prototype === null || prototype === Object.prototype;
+      } //# sourceMappingURL=is-plain-object.js.map
+
+      /***/
+    },
+
     /***/ 5660: /***/ function(__unused_webpack_module, exports) {
       "use strict";
 
@@ -9062,7 +9084,7 @@
       });
       exports["default"] = isError;
       exports.getProperError = getProperError;
-      var _isPlainObject = __webpack_require__(2288);
+      var _isPlainObject = __webpack_require__(8887);
       function isError(err) {
         return (
           typeof err === "object" &&
@@ -9089,30 +9111,6 @@
       /***/
     },
 
-    /***/ 2288: /***/ function(__unused_webpack_module, exports) {
-      "use strict";
-
-      Object.defineProperty(exports, "__esModule", {
-        value: true
-      });
-      exports.getObjectClassLabel = getObjectClassLabel;
-      exports.isPlainObject = isPlainObject;
-      function getObjectClassLabel(value) {
-        return Object.prototype.toString.call(value);
-      }
-      function isPlainObject(value) {
-        if (getObjectClassLabel(value) !== "[object Object]") {
-          return false;
-        }
-        const prototype = Object.getPrototypeOf(value);
-        return prototype === null || prototype === Object.prototype;
-      }
-
-      //# sourceMappingURL=is-plain-object.js.map
-
-      /***/
-    },
-
     /***/ 4522: /***/ function(
       __unused_webpack_module,
       exports,
Diff for index.html
@@ -19,7 +19,7 @@
       defer=""
     ></script>
     <script
-      src="/_next/static/chunks/main-dda21bde619fccde.js"
+      src="/_next/static/chunks/main-aaf11064276c90ab.js"
       defer=""
     ></script>
     <script
Diff for link.html
@@ -19,7 +19,7 @@
       defer=""
     ></script>
     <script
-      src="/_next/static/chunks/main-dda21bde619fccde.js"
+      src="/_next/static/chunks/main-aaf11064276c90ab.js"
       defer=""
     ></script>
     <script
Diff for withRouter.html
@@ -19,7 +19,7 @@
       defer=""
     ></script>
     <script
-      src="/_next/static/chunks/main-dda21bde619fccde.js"
+      src="/_next/static/chunks/main-aaf11064276c90ab.js"
       defer=""
     ></script>
     <script

Default Build with SWC (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js canary v12.0.9 vercel/next.js refs/heads/canary Change
buildDuration 18.2s 17.7s -559ms
buildDurationCached 3.6s 3.6s ⚠️ +21ms
nodeModulesSize 358 MB 358 MB ⚠️ +4.76 kB
Page Load Tests Overall increase ✓
vercel/next.js canary v12.0.9 vercel/next.js refs/heads/canary Change
/ failed reqs 0 0
/ total time (seconds) 3.428 3.316 -0.11
/ avg req/sec 729.3 753.96 +24.66
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 1.566 1.552 -0.01
/error-in-render avg req/sec 1596.44 1611.07 +14.63
Client Bundles (main, webpack, commons) Overall increase ⚠️
vercel/next.js canary v12.0.9 vercel/next.js refs/heads/canary Change
450.HASH.js gzip 179 B 179 B
framework-HASH.js gzip 42.3 kB 42.3 kB
main-HASH.js gzip 27.3 kB 27.3 kB ⚠️ +15 B
webpack-HASH.js gzip 1.44 kB 1.44 kB
Overall change 71.3 kB 71.3 kB ⚠️ +15 B
Legacy Client Bundles (polyfills)
vercel/next.js canary v12.0.9 vercel/next.js refs/heads/canary Change
polyfills-HASH.js gzip 31 kB 31 kB
Overall change 31 kB 31 kB
Client Pages
vercel/next.js canary v12.0.9 vercel/next.js refs/heads/canary Change
_app-HASH.js gzip 1.35 kB 1.35 kB
_error-HASH.js gzip 180 B 180 B
amp-HASH.js gzip 305 B 305 B
css-HASH.js gzip 321 B 321 B
dynamic-HASH.js gzip 2.36 kB 2.36 kB
head-HASH.js gzip 342 B 342 B
hooks-HASH.js gzip 911 B 911 B
image-HASH.js gzip 4.97 kB 4.97 kB
index-HASH.js gzip 256 B 256 B
link-HASH.js gzip 2.21 kB 2.21 kB
routerDirect..HASH.js gzip 314 B 314 B
script-HASH.js gzip 375 B 375 B
withRouter-HASH.js gzip 309 B 309 B
85e02e95b279..7e3.css gzip 107 B 107 B
Overall change 14.3 kB 14.3 kB
Client Build Manifests
vercel/next.js canary v12.0.9 vercel/next.js refs/heads/canary Change
_buildManifest.js gzip 459 B 459 B
Overall change 459 B 459 B
Rendered Page Sizes Overall decrease ✓
vercel/next.js canary v12.0.9 vercel/next.js refs/heads/canary Change
index.html gzip 531 B 531 B
link.html gzip 545 B 544 B -1 B
withRouter.html gzip 526 B 525 B -1 B
Overall change 1.6 kB 1.6 kB -2 B

Diffs

Diff for main-HASH.js
@@ -628,7 +628,7 @@
         document.getElementById("__NEXT_DATA__").textContent
       );
       window.__NEXT_DATA__ = data;
-      var version = "12.0.9";
+      var version = "12.0.10-canary.0";
       exports.version = version;
       var looseToArray = function(input) {
         return [].slice.call(input);
@@ -3876,6 +3876,28 @@
       /***/
     },
 
+    /***/ 8887: /***/ function(__unused_webpack_module, exports) {
+      "use strict";
+
+      Object.defineProperty(exports, "__esModule", {
+        value: true
+      });
+      exports.getObjectClassLabel = getObjectClassLabel;
+      exports.isPlainObject = isPlainObject;
+      function getObjectClassLabel(value) {
+        return Object.prototype.toString.call(value);
+      }
+      function isPlainObject(value) {
+        if (getObjectClassLabel(value) !== "[object Object]") {
+          return false;
+        }
+        var prototype = Object.getPrototypeOf(value);
+        return prototype === null || prototype === Object.prototype;
+      } //# sourceMappingURL=is-plain-object.js.map
+
+      /***/
+    },
+
     /***/ 5660: /***/ function(__unused_webpack_module, exports) {
       "use strict";
 
@@ -9062,7 +9084,7 @@
       });
       exports["default"] = isError;
       exports.getProperError = getProperError;
-      var _isPlainObject = __webpack_require__(2288);
+      var _isPlainObject = __webpack_require__(8887);
       function isError(err) {
         return (
           typeof err === "object" &&
@@ -9089,30 +9111,6 @@
       /***/
     },
 
-    /***/ 2288: /***/ function(__unused_webpack_module, exports) {
-      "use strict";
-
-      Object.defineProperty(exports, "__esModule", {
-        value: true
-      });
-      exports.getObjectClassLabel = getObjectClassLabel;
-      exports.isPlainObject = isPlainObject;
-      function getObjectClassLabel(value) {
-        return Object.prototype.toString.call(value);
-      }
-      function isPlainObject(value) {
-        if (getObjectClassLabel(value) !== "[object Object]") {
-          return false;
-        }
-        const prototype = Object.getPrototypeOf(value);
-        return prototype === null || prototype === Object.prototype;
-      }
-
-      //# sourceMappingURL=is-plain-object.js.map
-
-      /***/
-    },
-
     /***/ 4522: /***/ function(
       __unused_webpack_module,
       exports,
Diff for index.html
@@ -19,7 +19,7 @@
       defer=""
     ></script>
     <script
-      src="/_next/static/chunks/main-dda21bde619fccde.js"
+      src="/_next/static/chunks/main-aaf11064276c90ab.js"
       defer=""
     ></script>
     <script
Diff for link.html
@@ -19,7 +19,7 @@
       defer=""
     ></script>
     <script
-      src="/_next/static/chunks/main-dda21bde619fccde.js"
+      src="/_next/static/chunks/main-aaf11064276c90ab.js"
       defer=""
     ></script>
     <script
Diff for withRouter.html
@@ -19,7 +19,7 @@
       defer=""
     ></script>
     <script
-      src="/_next/static/chunks/main-dda21bde619fccde.js"
+      src="/_next/static/chunks/main-aaf11064276c90ab.js"
       defer=""
     ></script>
     <script

Please sign in to comment.