Skip to content

Commit 8aa9261

Browse files
committed
Enable proxy.ws option from the CLI
1 parent 3aad96c commit 8aa9261

4 files changed

Lines changed: 63 additions & 0 deletions

File tree

lib/cli/opts.start.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"https": "Enable SSL for local development",
1111
"directory": "Show a directory listing for the server",
1212
"proxy": "Proxy an existing server",
13+
"ws": "Proxy mode only - enable websocket proxying",
1314
"xip": "Use xip.io domain routing",
1415
"tunnel": "Use a public URL",
1516
"open": "Choose which URL is auto-opened (local, external or tunnel)",

lib/default-config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ module.exports = {
7171
* @property proxy
7272
* @type String|Object|Boolean
7373
* @param {String} [target]
74+
* @param {Boolean} [ws] - Enable websocket proxying
7475
* @param {Function|Array} [middleware]
7576
* @param {Function} [reqHeaders]
7677
* @param {Array} [proxyRes]

lib/options.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module.exports.update = function (options) {
1515
setMode(item);
1616
setScheme(item);
1717
setStartPath(item);
18+
setProxyWs(item);
1819
setServerOpts(item);
1920
setNamespace(item);
2021
fixSnippetOptions(item);
@@ -27,6 +28,17 @@ module.exports.update = function (options) {
2728
});
2829
};
2930

31+
/**
32+
* Move top-level ws options to proxy.ws
33+
* This is to allow it to be set from the CLI
34+
* @param item
35+
*/
36+
function setProxyWs(item) {
37+
if (item.get("ws") && item.get("mode") === "proxy") {
38+
item.setIn(["proxy", "ws"], true);
39+
}
40+
}
41+
3042
/**
3143
* @param item
3244
*/
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
"use strict";
2+
3+
var path = require("path");
4+
//var request = require("supertest");
5+
var assert = require("chai").assert;
6+
var connect = require("connect");
7+
var browserSync = require(path.resolve("./"));
8+
var serveStatic = require("serve-static");
9+
10+
var pkg = require(path.resolve("package.json"));
11+
var cli = require(path.resolve(pkg.bin));
12+
13+
describe("E2E CLI proxy + websockets test", function () {
14+
15+
var instance, server;
16+
17+
before(function (done) {
18+
19+
browserSync.reset();
20+
var app = connect();
21+
app.use(serveStatic("./test/fixtures"));
22+
server = app.listen();
23+
var proxytarget = "http://localhost:" + server.address().port;
24+
25+
cli({
26+
cli: {
27+
input: ["start"],
28+
flags: {
29+
proxy: proxytarget,
30+
open: false,
31+
online: false,
32+
logLevel: "silent",
33+
ws: true
34+
}
35+
},
36+
cb: function (err, bs) {
37+
instance = bs;
38+
done();
39+
}
40+
});
41+
});
42+
after(function () {
43+
server.close();
44+
instance.cleanup();
45+
});
46+
it("Adds the proxy.ws options", function () {
47+
assert.equal(instance.options.getIn(["proxy", "ws"]), true);
48+
});
49+
});

0 commit comments

Comments
 (0)