-
Notifications
You must be signed in to change notification settings - Fork 755
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(https): Ensure HTTPS option is used in legacy mode + top level, re:
- Loading branch information
1 parent
bb40075
commit 799c0a5
Showing
12 changed files
with
310 additions
and
432 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
"use strict"; | ||
|
||
var snippetUtils = require("./../snippet").utils; | ||
var _ = require("lodash"); | ||
var foxy = require("foxy"); | ||
|
||
/** | ||
* @param {BrowserSync} bs | ||
* @param {String} scripts | ||
* @returns {*} | ||
*/ | ||
module.exports = function createProxyServer (bs, scripts) { | ||
|
||
var options = bs.options; | ||
|
||
checkProxyTarget(options.get("proxy"), function (err) { | ||
if (err) { | ||
bs.events.emit("config:warn", {msg: err}); | ||
} | ||
}); | ||
|
||
var mw = [snippetUtils.getProxyMiddleware(scripts, options.getIn(["scriptPaths", "versioned"]))]; | ||
var pluginMw = bs.pluginManager.hook("server:middleware"); | ||
|
||
if (pluginMw.length) { | ||
mw = mw.concat(pluginMw); | ||
} | ||
|
||
var snippetOptions = options.get("snippetOptions").toJS(); | ||
var foxyServer = foxy(options.getIn(["proxy", "target"]), { | ||
rules: snippetUtils.getRegex(options.get("snippet"), options.get("snippetOptions")), | ||
whitelist: snippetOptions.whitelist, | ||
blacklist: snippetOptions.blacklist, | ||
middleware: mw, | ||
errHandler: function (err) { | ||
bs.logger.debug("{red:[proxy error]} %s", err.message); | ||
} | ||
} | ||
); | ||
|
||
return { | ||
server: foxyServer, | ||
app: foxyServer.app | ||
}; | ||
}; | ||
|
||
/** | ||
* @param {Object} proxy | ||
* @param {Function} cb | ||
*/ | ||
function checkProxyTarget (proxy, cb) { | ||
|
||
var chunks = []; | ||
var errored = false; | ||
|
||
function logError() { | ||
if (!errored) { | ||
cb("Proxy address not reachable - is your server running?"); | ||
errored = true; | ||
} | ||
} | ||
|
||
require("http").get(proxy.get("target"), function (res) { | ||
res.on("data", function (data) { | ||
chunks.push(data); | ||
}); | ||
}).on("error", function (err) { | ||
if (_.contains(["ENOTFOUND", "ECONNREFUSED"], err.code)) { | ||
logError(); | ||
} | ||
}).on("close", function () { | ||
if (!chunks.length) { | ||
logError(); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
"use strict"; | ||
|
||
var connect = require("connect"); | ||
var http = require("http"); | ||
|
||
/** | ||
* Create a server for the snippet | ||
* @param {BrowserSync} bs | ||
* @param scripts | ||
* @returns {*} | ||
*/ | ||
module.exports = function createSnippetServer (bs, scripts) { | ||
|
||
var app = connect(); | ||
|
||
app.use(bs.options.getIn(["scriptPaths", "versioned"]), scripts) | ||
.use(bs.options.getIn(["scriptPaths", "path"]), scripts); | ||
|
||
return { | ||
server: http.createServer(app), | ||
app: app | ||
}; | ||
}; |
Oops, something went wrong.