From fbff5661a77c5bc1e5883fb7beb0b9bc4ff7281d Mon Sep 17 00:00:00 2001 From: kellyrmilligan Date: Thu, 18 May 2017 16:58:58 -0500 Subject: [PATCH 1/5] started prefix work --- client/index.js | 6 ++++++ lib/Server.js | 3 ++- lib/optionsSchema.json | 4 ++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/client/index.js b/client/index.js index 1da6885b71..a98ca7070a 100644 --- a/client/index.js +++ b/client/index.js @@ -150,6 +150,12 @@ if(hostname && (self.location.protocol === "https:" || urlParts.hostname === "0. protocol = self.location.protocol; } +var rootPathName = url.parse(__webpack_public_path__).pathname || ""; // eslint-disable-line no-undef + +if(rootPathName.length > 1) { + rootPathName = rootPathName.replace(/\/+$/, ""); +} + var socketUrl = url.format({ protocol: protocol, auth: urlParts.auth, diff --git a/lib/Server.js b/lib/Server.js index 1a2fe5ccab..9b550ff65b 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -37,6 +37,7 @@ function Server(compiler, options) { this.clientOverlay = options.overlay; this.disableHostCheck = !!options.disableHostCheck; this.publicHost = options.public; + this.sockjsPrefix = options.sockjsPrefix || "" this.sockets = []; this.contentBaseWatchers = []; @@ -468,7 +469,7 @@ Server.prototype.listen = function(port, hostname) { }); sockServer.installHandlers(this.listeningApp, { - prefix: "/sockjs-node" + prefix: `${this.sockjsPrefix}/sockjs-node` }); return returnValue; } diff --git a/lib/optionsSchema.json b/lib/optionsSchema.json index 49c60db1ee..86bb2d0cdb 100644 --- a/lib/optionsSchema.json +++ b/lib/optionsSchema.json @@ -43,6 +43,10 @@ } ] }, + "sockjsPrefix": { + "description": "Optional prefix for the sockjs handler to be mounted to.", + "type": "string" + }, "socket": { "description": "The Unix socket to listen to (instead of on a host).", "type": "string" From 217936b53bd61ff1bc7aa354c3c16d633e3c6e53 Mon Sep 17 00:00:00 2001 From: kellyrmilligan Date: Fri, 19 May 2017 09:53:28 -0500 Subject: [PATCH 2/5] updates to prefix work --- client/index.js | 4 +++- examples/node-api-simple/app.js | 2 +- examples/node-api-simple/index.html | 2 +- examples/node-api-simple/server.js | 11 ++++++++++- examples/node-api-simple/webpack.config.js | 5 +++-- 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/client/index.js b/client/index.js index a98ca7070a..9b5f282194 100644 --- a/client/index.js +++ b/client/index.js @@ -156,12 +156,14 @@ if(rootPathName.length > 1) { rootPathName = rootPathName.replace(/\/+$/, ""); } +var sockjsPath = rootPathName + "/sockjs-node"; + var socketUrl = url.format({ protocol: protocol, auth: urlParts.auth, hostname: hostname, port: (urlParts.port === "0") ? self.location.port : urlParts.port, - pathname: urlParts.path == null || urlParts.path === "/" ? "/sockjs-node" : urlParts.path + pathname: urlParts.path == null || urlParts.path === "/" ? sockjsPath : urlParts.path }); socket(socketUrl, onSocketMsg); diff --git a/examples/node-api-simple/app.js b/examples/node-api-simple/app.js index b8b8e7ced6..731be32436 100644 --- a/examples/node-api-simple/app.js +++ b/examples/node-api-simple/app.js @@ -1,4 +1,4 @@ -document.write("It's working."); +document.write("It's working under a subapp"); // This results in a warning: if(!window) require("./" + window + "parseable.js"); diff --git a/examples/node-api-simple/index.html b/examples/node-api-simple/index.html index 0445fdf419..86fc28b105 100644 --- a/examples/node-api-simple/index.html +++ b/examples/node-api-simple/index.html @@ -1,7 +1,7 @@ - +

Example: Node.js API - Simple

diff --git a/examples/node-api-simple/server.js b/examples/node-api-simple/server.js index 9ba0fa75dc..e2307d5360 100644 --- a/examples/node-api-simple/server.js +++ b/examples/node-api-simple/server.js @@ -1,6 +1,7 @@ "use strict"; const Webpack = require("webpack"); +const path = require("path"); const WebpackDevServer = require("../../lib/Server"); const webpackConfig = require("./webpack.config"); @@ -8,7 +9,15 @@ const compiler = Webpack(webpackConfig); const server = new WebpackDevServer(compiler, { stats: { colors: true - } + }, + contentBase: path.resolve(__dirname), + watchContentBase: true, + sockjsPrefix: "/subapp", + publicPath: "/subapp/", + historyApiFallback: { + disableDotRule: true, + index: "/subapp/" + }, }); server.listen(8080, "127.0.0.1", function() { diff --git a/examples/node-api-simple/webpack.config.js b/examples/node-api-simple/webpack.config.js index 918946f122..4afd582e86 100644 --- a/examples/node-api-simple/webpack.config.js +++ b/examples/node-api-simple/webpack.config.js @@ -2,6 +2,7 @@ module.exports = { context: __dirname, entry: ["./app.js", "../../client/index.js?http://localhost:8080/"], output: { - filename: "bundle.js" - } + filename: "bundle.js", + publicPath: "/subapp/" + }, } From 0ab4e3c28c006daff70de5ad81ded43076e6c314 Mon Sep 17 00:00:00 2001 From: kellyrmilligan Date: Fri, 19 May 2017 09:54:41 -0500 Subject: [PATCH 3/5] updates to example for sockjsprefix --- examples/node-api-simple/app.js | 2 +- examples/node-api-simple/index.html | 2 +- examples/node-api-simple/server.js | 11 +------- examples/node-api-simple/webpack.config.js | 5 ++-- examples/node-api-sockjs-prefix/README.md | 15 +++++++++++ examples/node-api-sockjs-prefix/app.js | 7 ++++++ examples/node-api-sockjs-prefix/index.html | 9 +++++++ examples/node-api-sockjs-prefix/server.js | 25 +++++++++++++++++++ .../node-api-sockjs-prefix/webpack.config.js | 8 ++++++ 9 files changed, 69 insertions(+), 15 deletions(-) create mode 100644 examples/node-api-sockjs-prefix/README.md create mode 100644 examples/node-api-sockjs-prefix/app.js create mode 100644 examples/node-api-sockjs-prefix/index.html create mode 100644 examples/node-api-sockjs-prefix/server.js create mode 100644 examples/node-api-sockjs-prefix/webpack.config.js diff --git a/examples/node-api-simple/app.js b/examples/node-api-simple/app.js index 731be32436..b8b8e7ced6 100644 --- a/examples/node-api-simple/app.js +++ b/examples/node-api-simple/app.js @@ -1,4 +1,4 @@ -document.write("It's working under a subapp"); +document.write("It's working."); // This results in a warning: if(!window) require("./" + window + "parseable.js"); diff --git a/examples/node-api-simple/index.html b/examples/node-api-simple/index.html index 86fc28b105..0445fdf419 100644 --- a/examples/node-api-simple/index.html +++ b/examples/node-api-simple/index.html @@ -1,7 +1,7 @@ - +

Example: Node.js API - Simple

diff --git a/examples/node-api-simple/server.js b/examples/node-api-simple/server.js index e2307d5360..9ba0fa75dc 100644 --- a/examples/node-api-simple/server.js +++ b/examples/node-api-simple/server.js @@ -1,7 +1,6 @@ "use strict"; const Webpack = require("webpack"); -const path = require("path"); const WebpackDevServer = require("../../lib/Server"); const webpackConfig = require("./webpack.config"); @@ -9,15 +8,7 @@ const compiler = Webpack(webpackConfig); const server = new WebpackDevServer(compiler, { stats: { colors: true - }, - contentBase: path.resolve(__dirname), - watchContentBase: true, - sockjsPrefix: "/subapp", - publicPath: "/subapp/", - historyApiFallback: { - disableDotRule: true, - index: "/subapp/" - }, + } }); server.listen(8080, "127.0.0.1", function() { diff --git a/examples/node-api-simple/webpack.config.js b/examples/node-api-simple/webpack.config.js index 4afd582e86..918946f122 100644 --- a/examples/node-api-simple/webpack.config.js +++ b/examples/node-api-simple/webpack.config.js @@ -2,7 +2,6 @@ module.exports = { context: __dirname, entry: ["./app.js", "../../client/index.js?http://localhost:8080/"], output: { - filename: "bundle.js", - publicPath: "/subapp/" - }, + filename: "bundle.js" + } } diff --git a/examples/node-api-sockjs-prefix/README.md b/examples/node-api-sockjs-prefix/README.md new file mode 100644 index 0000000000..1ce352b141 --- /dev/null +++ b/examples/node-api-sockjs-prefix/README.md @@ -0,0 +1,15 @@ +# Node.js API - Simple + +```shell +node server.js +``` + +Starts a simple webpack-dev-server setup via the Node API. Open `http://localhost:8080/` to go the app. + +## What should happen + +In the app you should see "It's working." + +In `app.js`, uncomment the code that results in an error and save. This error should be visible in the CLI and devtools. + +Then, in `app.js`, uncomment the code that results in a warning. This warning should be visible in the CLI and devtools. diff --git a/examples/node-api-sockjs-prefix/app.js b/examples/node-api-sockjs-prefix/app.js new file mode 100644 index 0000000000..731be32436 --- /dev/null +++ b/examples/node-api-sockjs-prefix/app.js @@ -0,0 +1,7 @@ +document.write("It's working under a subapp"); + +// This results in a warning: +if(!window) require("./" + window + "parseable.js"); + +// This results in an error: +// if(!window) require("test"); diff --git a/examples/node-api-sockjs-prefix/index.html b/examples/node-api-sockjs-prefix/index.html new file mode 100644 index 0000000000..86fc28b105 --- /dev/null +++ b/examples/node-api-sockjs-prefix/index.html @@ -0,0 +1,9 @@ + + + + + + +

Example: Node.js API - Simple

+ + diff --git a/examples/node-api-sockjs-prefix/server.js b/examples/node-api-sockjs-prefix/server.js new file mode 100644 index 0000000000..e2307d5360 --- /dev/null +++ b/examples/node-api-sockjs-prefix/server.js @@ -0,0 +1,25 @@ +"use strict"; + +const Webpack = require("webpack"); +const path = require("path"); +const WebpackDevServer = require("../../lib/Server"); +const webpackConfig = require("./webpack.config"); + +const compiler = Webpack(webpackConfig); +const server = new WebpackDevServer(compiler, { + stats: { + colors: true + }, + contentBase: path.resolve(__dirname), + watchContentBase: true, + sockjsPrefix: "/subapp", + publicPath: "/subapp/", + historyApiFallback: { + disableDotRule: true, + index: "/subapp/" + }, +}); + +server.listen(8080, "127.0.0.1", function() { + console.log("Starting server on http://localhost:8080"); +}); diff --git a/examples/node-api-sockjs-prefix/webpack.config.js b/examples/node-api-sockjs-prefix/webpack.config.js new file mode 100644 index 0000000000..4afd582e86 --- /dev/null +++ b/examples/node-api-sockjs-prefix/webpack.config.js @@ -0,0 +1,8 @@ +module.exports = { + context: __dirname, + entry: ["./app.js", "../../client/index.js?http://localhost:8080/"], + output: { + filename: "bundle.js", + publicPath: "/subapp/" + }, +} From 66bed53b933a750671ed5c58551af69f179e60ad Mon Sep 17 00:00:00 2001 From: kellyrmilligan Date: Fri, 19 May 2017 10:40:03 -0500 Subject: [PATCH 4/5] fix tests typo from fix --- test/Validation.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Validation.test.js b/test/Validation.test.js index 2be20c4fc3..efe31b7364 100644 --- a/test/Validation.test.js +++ b/test/Validation.test.js @@ -40,7 +40,7 @@ describe("Validation", function() { config: { asdf: true }, message: [ " - configuration has an unknown property 'asdf'. These properties are valid:", - " object { hot?, hotOnly?, lazy?, host?, filename?, publicPath?, port?, socket?, " + + " object { hot?, hotOnly?, lazy?, host?, filename?, publicPath?, port?, sockjsPrefix?, socket?, " + "watchOptions?, headers?, clientLogLevel?, overlay?, key?, cert?, ca?, pfx?, pfxPassphrase?, " + "inline?, disableHostCheck?, public?, https?, contentBase?, watchContentBase?, open?, features?, " + "compress?, proxy?, historyApiFallback?, staticOptions?, setup?, stats?, reporter?, " + From 6078d07cb7690ce9fc75e671b359b139a399333d Mon Sep 17 00:00:00 2001 From: kellyrmilligan Date: Thu, 27 Jul 2017 08:32:57 -0500 Subject: [PATCH 5/5] fix linting from merge conflict --- lib/Server.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Server.js b/lib/Server.js index 782bc02bda..07ff2878ab 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -41,7 +41,7 @@ function Server(compiler, options) { this.clientOverlay = options.overlay; this.disableHostCheck = !!options.disableHostCheck; this.publicHost = options.public; - this.allowedHosts = options.allowedHosts; + this.allowedHosts = options.allowedHosts; this.sockjsPrefix = options.sockjsPrefix || "" this.sockets = []; this.contentBaseWatchers = [];