From b5fa8d47f32d665dc5901141d492cca4b7e2e0da Mon Sep 17 00:00:00 2001
From: Leo Lamprecht <mindrun@icloud.com>
Date: Tue, 29 May 2018 12:29:18 +0200
Subject: [PATCH 1/3] Added `--single` for SPA rewrite preset

---
 bin/serve.js | 17 ++++++++++++++++-
 package.json |  2 +-
 yarn.lock    |  6 +++---
 3 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/bin/serve.js b/bin/serve.js
index f26f6747..1a3cfae1 100755
--- a/bin/serve.js
+++ b/bin/serve.js
@@ -70,6 +70,8 @@ const getHelp = () => chalk`
 
       -d, --debug                         Show debugging information
 
+      -s, --single                        Rewrite all requests to \`index.html\`
+
   {bold ENDPOINTS}
 
       Listen endpoints (specified by the {bold --listen} or {bold -l} options above) instruct {cyan serve}
@@ -237,11 +239,13 @@ const loadConfig = async (cwd, entry) => {
 			'--help': Boolean,
 			'--version': Boolean,
 			'--listen': [parseEndpoint],
+			'--single': Boolean,
 			'--debug': Boolean,
 			'-h': '--help',
 			'-v': '--version',
 			'-l': '--listen',
-			'-d': '--debug'
+			'-d': '--debug',
+			'-s': '--single'
 		});
 	} catch (err) {
 		console.error(error(err.message));
@@ -275,6 +279,17 @@ const loadConfig = async (cwd, entry) => {
 
 	const config = await loadConfig(cwd, entry);
 
+	if (args['--single']) {
+		const {rewrites} = config;
+		const existingRewrites = Array.isArray(rewrites) ? rewrites : [];
+
+		// As the first rewrite rule, make `--single` work
+		config.rewrites = [{
+			source: '**',
+			destination: '/index.html'
+		}, ...existingRewrites];
+	}
+
 	for (const endpoint of args['--listen']) {
 		startEndpoint(endpoint, config);
 	}
diff --git a/package.json b/package.json
index b5f82fb4..1c3be7e6 100644
--- a/package.json
+++ b/package.json
@@ -40,7 +40,7 @@
     "ajv": "6.5.0",
     "arg": "2.0.0",
     "chalk": "2.4.1",
-    "serve-handler": "2.3.11",
+    "serve-handler": "2.3.12",
     "update-check": "1.5.2"
   }
 }
diff --git a/yarn.lock b/yarn.lock
index b82f16cf..46aad3d4 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -804,9 +804,9 @@ semver@^5.3.0:
   version "5.5.0"
   resolved "https://registry.yarnpkg.com/semver/-/semver-5.5.0.tgz#dc4bbc7a6ca9d916dee5d43516f0092b58f7b8ab"
 
-serve-handler@2.3.11:
-  version "2.3.11"
-  resolved "https://registry.yarnpkg.com/serve-handler/-/serve-handler-2.3.11.tgz#e04b5950b7f7874adc47474ac75347dc79ceb097"
+serve-handler@2.3.12:
+  version "2.3.12"
+  resolved "https://registry.yarnpkg.com/serve-handler/-/serve-handler-2.3.12.tgz#7c4f402753c74a7ff33b8607130b28bc45a07222"
   dependencies:
     bytes "3.0.0"
     fast-url-parser "1.1.3"

From 744b18db6e100c3ed141cf4533072d713f781db6 Mon Sep 17 00:00:00 2001
From: Leo Lamprecht <mindrun@icloud.com>
Date: Tue, 29 May 2018 12:38:59 +0200
Subject: [PATCH 2/3] Allow `--listen` to accept ports directly

---
 bin/serve.js | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/bin/serve.js b/bin/serve.js
index 1a3cfae1..4a07a775 100755
--- a/bin/serve.js
+++ b/bin/serve.js
@@ -77,6 +77,10 @@ const getHelp = () => chalk`
       Listen endpoints (specified by the {bold --listen} or {bold -l} options above) instruct {cyan serve}
       to listen on one or more interfaces/ports, UNIX domain sockets, or Windows named pipes.
 
+      For TCP ports on hostname "localhost":
+
+          {bold $} {cyan serve} -l {underline 1234}
+
       For TCP (traditional host/port) endpoints:
 
           {bold $} {cyan serve} -l tcp://{underline hostname}:{underline 1234}
@@ -91,6 +95,10 @@ const getHelp = () => chalk`
 `;
 
 const parseEndpoint = str => {
+	if (!isNaN(str)) {
+		return [str];
+	}
+
 	const url = new URL(str);
 
 	switch (url.protocol) {

From 996b80d074106f7939ab57ee05431aa9e8572bab Mon Sep 17 00:00:00 2001
From: Leo Lamprecht <mindrun@icloud.com>
Date: Tue, 29 May 2018 12:42:48 +0200
Subject: [PATCH 3/3] Be more clear in usage

---
 bin/serve.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/bin/serve.js b/bin/serve.js
index 4a07a775..29c193c6 100755
--- a/bin/serve.js
+++ b/bin/serve.js
@@ -70,7 +70,7 @@ const getHelp = () => chalk`
 
       -d, --debug                         Show debugging information
 
-      -s, --single                        Rewrite all requests to \`index.html\`
+      -s, --single                        Rewrite all not-found requests to \`index.html\`
 
   {bold ENDPOINTS}