Template Upload
This commit is contained in:
BIN
node_modules/browser-sync/lib/server/certs/browsersync.pfx
generated
vendored
Normal file
BIN
node_modules/browser-sync/lib/server/certs/browsersync.pfx
generated
vendored
Normal file
Binary file not shown.
6
node_modules/browser-sync/lib/server/certs/gen.sh
generated
vendored
Normal file
6
node_modules/browser-sync/lib/server/certs/gen.sh
generated
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
openssl genrsa -des3 -out server.key 2048
|
||||
openssl req -new -key server.key -out server.csr
|
||||
openssl x509 -req -days 3650 -in server.csr -signkey server.key -out server.crt
|
||||
cp server.key server.key.copy
|
||||
openssl rsa -in server.key.copy -out server.key
|
||||
rm server.key.copy
|
19
node_modules/browser-sync/lib/server/certs/server.crt
generated
vendored
Normal file
19
node_modules/browser-sync/lib/server/certs/server.crt
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDBjCCAe4CCQCir/8eGDIE/jANBgkqhkiG9w0BAQsFADBFMQswCQYDVQQGEwJH
|
||||
QjETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50ZXJuZXQgV2lkZ2l0
|
||||
cyBQdHkgTHRkMB4XDTE3MDQxMDExNDcyNloXDTI3MDQwODExNDcyNlowRTELMAkG
|
||||
A1UEBhMCR0IxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoMGEludGVybmV0
|
||||
IFdpZGdpdHMgUHR5IEx0ZDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB
|
||||
AMRLR2crKB4X/9pM3gR641iDscZWW3aqo70nUDxzo5Bhk8uupqz0EfdRoCLCUeQi
|
||||
xVp3HJ1HqnilMW7dETGGkDHKdxJRjrkBrYHhE3Kw/LCC4tEb400F6Ikm6OudVPIB
|
||||
P+CuwfNAw70KHSx/CtIrbTz0HhDC6XN0azp39pDLRBnWWluz3iU+rFLMx7YT2Q8k
|
||||
1nQAwcXkzLjeU7txAt2pYGQUgvBQETO5RI7QQ0CmwaV4gfHWGABBTX34WQun7g1Q
|
||||
YukrG3/4fVeNLzGW787FKCvL07BTymJTwXXbTTPXg4chw9p+YkLLPrr+AOVe/PF1
|
||||
MJppDT3gKdKMHFo3vMycUf0CAwEAATANBgkqhkiG9w0BAQsFAAOCAQEAEVmUYRrT
|
||||
fCQmBDox3evqj4n8dJVStjgdw/7BPkm49SmGtaxsST/eUSGwT7dTvZBLov6BK/OW
|
||||
+arhHZIvUY/DXlsV4NfCM4TK8KVefrwgd8ZsfQJW73L+FB0IOAY/6s+YKHm/wQGF
|
||||
ptSOycJvEltsqfIegtYcvvD6c6SkSOvqApaF+Ai10+yiLe20KyOvM3PefZLV7mFE
|
||||
0zCNyglZ75HftvHHV0wh82T2Et/R+txH+6dTwh065Dd6rrDzljtcAd2HC7B26ERK
|
||||
dA2zJd9Y4eMz8osacmG/afVuR9rqtFGwdyZ1Kb5xQRzGWlrjvSmAFUx9W9iA4Ilv
|
||||
3+56a5njSTFYKw==
|
||||
-----END CERTIFICATE-----
|
17
node_modules/browser-sync/lib/server/certs/server.csr
generated
vendored
Normal file
17
node_modules/browser-sync/lib/server/certs/server.csr
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
-----BEGIN CERTIFICATE REQUEST-----
|
||||
MIICoTCCAYkCAQAwRTELMAkGA1UEBhMCR0IxEzARBgNVBAgMClNvbWUtU3RhdGUx
|
||||
ITAfBgNVBAoMGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDCCASIwDQYJKoZIhvcN
|
||||
AQEBBQADggEPADCCAQoCggEBAMRLR2crKB4X/9pM3gR641iDscZWW3aqo70nUDxz
|
||||
o5Bhk8uupqz0EfdRoCLCUeQixVp3HJ1HqnilMW7dETGGkDHKdxJRjrkBrYHhE3Kw
|
||||
/LCC4tEb400F6Ikm6OudVPIBP+CuwfNAw70KHSx/CtIrbTz0HhDC6XN0azp39pDL
|
||||
RBnWWluz3iU+rFLMx7YT2Q8k1nQAwcXkzLjeU7txAt2pYGQUgvBQETO5RI7QQ0Cm
|
||||
waV4gfHWGABBTX34WQun7g1QYukrG3/4fVeNLzGW787FKCvL07BTymJTwXXbTTPX
|
||||
g4chw9p+YkLLPrr+AOVe/PF1MJppDT3gKdKMHFo3vMycUf0CAwEAAaAXMBUGCSqG
|
||||
SIb3DQEJBzEIDAYxMjM0NTYwDQYJKoZIhvcNAQELBQADggEBABlVUaWK/UUovgPZ
|
||||
+rqNG8/j6aggSCCye9CkauLB/WqhQFfLl9lWTYdUVmWweNU0SJwDU9lWF/TngipF
|
||||
RZs6501DkXKxaDT9/3JYg4lRz6zHLy+a77pavJOeN0+cFAPZZuGyxZvYHFYPVSVH
|
||||
EeJL6bO/nZ/ARgIp0YNkQblDarxq1ARj7YT1Z24D5KgO1kQ55+fCY/wtct8TLGk9
|
||||
ujvWBbFEBSrJCDjRQeSctlP5qG8yfeJqZwZzo4PQMUwABhNLGUz0z0ceK8W1QnOm
|
||||
T+nCN5Fni04wO4dAZvYPp6wmU0Gpi2XBihbFl9CT3B5AmJmM8hQVpuQlmXeXT0FO
|
||||
pOZFpko=
|
||||
-----END CERTIFICATE REQUEST-----
|
27
node_modules/browser-sync/lib/server/certs/server.key
generated
vendored
Normal file
27
node_modules/browser-sync/lib/server/certs/server.key
generated
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
MIIEogIBAAKCAQEAxEtHZysoHhf/2kzeBHrjWIOxxlZbdqqjvSdQPHOjkGGTy66m
|
||||
rPQR91GgIsJR5CLFWnccnUeqeKUxbt0RMYaQMcp3ElGOuQGtgeETcrD8sILi0Rvj
|
||||
TQXoiSbo651U8gE/4K7B80DDvQodLH8K0ittPPQeEMLpc3RrOnf2kMtEGdZaW7Pe
|
||||
JT6sUszHthPZDyTWdADBxeTMuN5Tu3EC3algZBSC8FARM7lEjtBDQKbBpXiB8dYY
|
||||
AEFNffhZC6fuDVBi6Ssbf/h9V40vMZbvzsUoK8vTsFPKYlPBddtNM9eDhyHD2n5i
|
||||
Qss+uv4A5V788XUwmmkNPeAp0owcWje8zJxR/QIDAQABAoIBADbeT/wvnQwkazkL
|
||||
CXg5HXltfnDRTMmz0wcZiR0MueiuzdA+ZoqrwqXeJCPzK07YxU+PQelY0fbdPh8e
|
||||
HiM42O+CB5yQPZPLO0O1tWj2vftc6qfG4tdx0lkcDjlmBguLe96DGuWy8cPSousA
|
||||
K/cpemRyXEEVKopCPYLfa4V3u/Z4be2U/39KNjVkHFhSdSYQl6ferhEfUPwTPi7O
|
||||
7l1/QUBabqN5FzNc2TeMVhhcJkXtYqF3RxGsaRfT0lK/j2hpbX7Bn2T0CfA/40jY
|
||||
2OCERqFPfZWx/ShTT52b3fyX/FEua7Nukq/MZdYZou63dDIjCQQyTJSflX6lVojO
|
||||
SuUoumECgYEA6CSkLiKcRLlTfec3LkjqkWtXR5ibL33g/H1fsZEQKFOyMbIXpUkX
|
||||
Hybpku8NGeetjKynO3yRirp+NiBHGPn3cHc9WJ5GGG1ew9hRQ9QzyC3Tit15TDbu
|
||||
J8i50/MaQHZSiUCnPQ/ceIZCNz8STcsEz87o/7utRLJKOvIIAPj+/8kCgYEA2Hd/
|
||||
v5oUroMRbtzPtMJDMHiGEQyNxEGDNqcuxgXSmiEEqPLfk2qR3yLffzA9UQOg4wkX
|
||||
/dSXsyomPriKWTvADXu1lNdkPGmW/1tk+onnHu6qgOalva30ZKhtteVjUqxEJEke
|
||||
mHhNHyIVuj6lExLw9LZhVvzoOi+aj4AD+DRS4pUCgYBEtuveOCJ3eUAMiY9c5PqB
|
||||
9vsL11FAOouJUXcs8VqOBVA+w4+aPktYzkTfWGFRZLGLbWPHCPVv0gof7Wf+Laef
|
||||
o7wF6junaWBeqj5LzJlTTLVMaohIFg5iuli/Mzt3D08ZD4kxWuuQxXT+M24wlsKi
|
||||
3IU9hYkhR4EPd6sE1q9seQKBgEpQRBAgModywbJgpgH1SyHBzqzdtXGx1/0USg97
|
||||
gkCdoz7pGm4+gNOs4jOE+Rft+fbXcWAX8vh0OOsBaaWWyKkYVk9B3syKp2cFFlaY
|
||||
rzrETs6v4CiNJsDDvd5bYMzKDR6z54gKjNdqWTE2Pm+c6hHo5uP5MTSAkTxAg5xb
|
||||
QjU9AoGAaYPXlm3IKVO12FgNg/ffduooi0PKa1yRNJGnhpQKNvBQXs8eV+CQ83aK
|
||||
kQHUExuJDrOfsC2iwF/2ZywXhEfbhL7ar0aw5zrhV+r7qvYFWxu/YoLoNVMDByw5
|
||||
wAN0oIbsGWYmtIIti8+b9IcacTbAZ79ctlTLb1HCyPMosHxDkv8=
|
||||
-----END RSA PRIVATE KEY-----
|
95
node_modules/browser-sync/lib/server/index.js
generated
vendored
Normal file
95
node_modules/browser-sync/lib/server/index.js
generated
vendored
Normal file
@ -0,0 +1,95 @@
|
||||
"use strict";
|
||||
|
||||
var enableDestroy = require("server-destroy");
|
||||
var _ = require("../../lodash.custom");
|
||||
|
||||
/**
|
||||
* Browsersync server
|
||||
* Three available modes: Snippet, Server or Proxy
|
||||
*/
|
||||
module.exports.plugin = function (bs) {
|
||||
|
||||
var debug = bs.debug;
|
||||
var proxy = bs.options.get("proxy");
|
||||
var type = bs.options.get("mode");
|
||||
|
||||
var bsServer = createServer(bs);
|
||||
|
||||
if (type === "server" || type === "snippet") {
|
||||
debug("Static Server running ({magenta:%s}) ...", bs.options.get("scheme"));
|
||||
}
|
||||
|
||||
if (proxy) {
|
||||
debug("Proxy running, proxing: {magenta:%s}", proxy.get("target"));
|
||||
}
|
||||
|
||||
if (bsServer) {
|
||||
|
||||
/**
|
||||
* Allow server to be destroyed gracefully
|
||||
*/
|
||||
enableDestroy(bsServer.server);
|
||||
|
||||
/**
|
||||
* Listen on the available port
|
||||
*/
|
||||
bsServer.server.listen(bs.options.get("port"));
|
||||
|
||||
/**
|
||||
* Hack to deal with https://github.com/socketio/socket.io/issues/1602#issuecomment-224270022
|
||||
*/
|
||||
bs.registerCleanupTask(function () {
|
||||
if (bs.io && bs.io.sockets) {
|
||||
setCloseReceived(bs.io.sockets);
|
||||
}
|
||||
if (bs.ui && bs.ui.socket) {
|
||||
setCloseReceived(bs.ui.socket);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Destroy the server on cleanup
|
||||
*/
|
||||
bs.registerCleanupTask(function () {
|
||||
bsServer.server.destroy();
|
||||
});
|
||||
}
|
||||
|
||||
function setCloseReceived(io) {
|
||||
Object.keys(io.sockets).forEach(function (key) {
|
||||
_.set(io.sockets[key], "conn.transport.socket._closeReceived", true);
|
||||
});
|
||||
}
|
||||
|
||||
debug("Running mode: %s", type.toUpperCase());
|
||||
|
||||
return {
|
||||
server: bsServer.server,
|
||||
app: bsServer.app
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Launch the server for serving the client JS plus static files
|
||||
* @param {BrowserSync} bs
|
||||
* @returns {{staticServer: (http.Server), proxyServer: (http.Server)}}
|
||||
*/
|
||||
function createServer (bs) {
|
||||
|
||||
var proxy = bs.options.get("proxy");
|
||||
var server = bs.options.get("server");
|
||||
|
||||
if (!proxy && !server) {
|
||||
return require("./snippet-server")(bs);
|
||||
}
|
||||
|
||||
if (proxy) {
|
||||
return require("./proxy-server")(bs);
|
||||
}
|
||||
|
||||
if (server) {
|
||||
return require("./static-server")(bs);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.createServer = createServer;
|
195
node_modules/browser-sync/lib/server/proxy-server.js
generated
vendored
Normal file
195
node_modules/browser-sync/lib/server/proxy-server.js
generated
vendored
Normal file
@ -0,0 +1,195 @@
|
||||
"use strict";
|
||||
|
||||
var httpProxy = require("http-proxy");
|
||||
var utils = require("./utils");
|
||||
var proxyUtils = require("./proxy-utils");
|
||||
var Immutable = require("immutable");
|
||||
var Map = require("immutable").Map;
|
||||
var List = require("immutable").List;
|
||||
|
||||
/**
|
||||
* Default options that are passed along to http-proxy
|
||||
*/
|
||||
var defaultHttpProxyOptions = Map({
|
||||
/**
|
||||
* This ensures targets are more likely to
|
||||
* accept each request
|
||||
*/
|
||||
changeOrigin: true,
|
||||
/**
|
||||
* This handles redirects
|
||||
*/
|
||||
autoRewrite: true,
|
||||
/**
|
||||
* This allows our self-signed certs to be used for development
|
||||
*/
|
||||
secure: false,
|
||||
ws: true
|
||||
});
|
||||
|
||||
var defaultCookieOptions = Map({
|
||||
stripDomain: true
|
||||
});
|
||||
|
||||
var ProxyOption = Immutable.Record({
|
||||
route: "",
|
||||
target: "",
|
||||
rewriteRules: true,
|
||||
/**
|
||||
* Functions to be called on proxy request
|
||||
* with args [proxyReq, req, res, options]
|
||||
*/
|
||||
proxyReq: List([]),
|
||||
/**
|
||||
* Functions to be called on proxy response
|
||||
* with args [proxyRes, req, res]
|
||||
*/
|
||||
proxyRes: List([]),
|
||||
/**
|
||||
* Functions to be called on proxy response
|
||||
* with args [proxyReq, req, socket, options, head]
|
||||
*/
|
||||
proxyReqWs: List([]),
|
||||
errHandler: undefined,
|
||||
url: Map({}),
|
||||
proxyOptions: Map(defaultHttpProxyOptions),
|
||||
cookies: Map(defaultCookieOptions),
|
||||
ws: false,
|
||||
middleware: List([]),
|
||||
reqHeaders: undefined
|
||||
});
|
||||
|
||||
/**
|
||||
* @param {BrowserSync} bs
|
||||
* @param {String} scripts
|
||||
* @returns {*}
|
||||
*/
|
||||
module.exports = function createProxyServer (bs) {
|
||||
|
||||
var opt = new ProxyOption().mergeDeep(bs.options.get("proxy"));
|
||||
var proxy = httpProxy.createProxyServer(opt.get("proxyOptions").set("target", opt.get("target")).toJS());
|
||||
var target = opt.get("target");
|
||||
var proxyReq = getProxyReqFunctions(opt.get("proxyReq"), opt, bs);
|
||||
var proxyRes = getProxyResFunctions(opt.get("proxyRes"), opt);
|
||||
var proxyResWs = opt.get("proxyReqWs");
|
||||
bs.options = bs.options.update("middleware", function (mw) {
|
||||
return mw.concat({
|
||||
id: "Browsersync Proxy",
|
||||
route: opt.get("route"),
|
||||
handle: function (req, res) {
|
||||
proxy.web(req, res, {
|
||||
target: target
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var app = utils.getBaseApp(bs);
|
||||
|
||||
/**
|
||||
* @type {*|{server, app}}
|
||||
*/
|
||||
var browserSyncServer = utils.getServer(app, bs.options);
|
||||
browserSyncServer.proxy = proxy;
|
||||
|
||||
if (opt.get("ws")) {
|
||||
// debug(`+ ws upgrade for: ${x.get("target")}`);
|
||||
browserSyncServer.server.on("upgrade", function (req, socket, head) {
|
||||
proxy.ws(req, socket, head);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Add any user provided functions for proxyReq, proxyReqWs and proxyRes
|
||||
*/
|
||||
applyFns("proxyReq", proxyReq);
|
||||
applyFns("proxyRes", proxyRes);
|
||||
applyFns("proxyReqWs", proxyResWs);
|
||||
|
||||
/**
|
||||
* Handle Proxy errors
|
||||
*/
|
||||
proxy.on("error", function (err) {
|
||||
if (typeof opt.get("errHandler") === "function") {
|
||||
opt.get("errHandler").call(null, err);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Apply functions to proxy events
|
||||
* @param {string} name - the name of the http-proxy event
|
||||
* @param {Array} fns - functions to call on each event
|
||||
*/
|
||||
function applyFns (name, fns) {
|
||||
if (!List.isList(fns)) fns = [fns];
|
||||
proxy.on(name, function () {
|
||||
var args = arguments;
|
||||
fns.forEach(function(fn) {
|
||||
if (typeof fn === "function") {
|
||||
fn.apply(null, args);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return browserSyncServer;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param resFns
|
||||
* @returns {*}
|
||||
*/
|
||||
function getProxyResFunctions (resFns, opt) {
|
||||
if (opt.getIn(["cookies", "stripDomain"])) {
|
||||
return resFns.push(proxyUtils.checkCookies);
|
||||
}
|
||||
return resFns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param reqFns
|
||||
* @returns {*}
|
||||
*/
|
||||
function getProxyReqFunctions (reqFns, opt, bs) {
|
||||
|
||||
var reqHeaders = opt.getIn(["reqHeaders"]);
|
||||
|
||||
if (!reqHeaders) {
|
||||
return reqFns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Back-compat for old `reqHeaders` option here a
|
||||
* function was given that returned an object
|
||||
* where key:value was header-name:header-value
|
||||
* This didn't really work as it clobbered all other headers,
|
||||
* but it remains for the unlucky few who used it.
|
||||
*/
|
||||
if (typeof reqHeaders === "function") {
|
||||
var output = reqHeaders.call(bs, opt.toJS());
|
||||
if (Object.keys(output).length) {
|
||||
return reqFns.concat(function (proxyReq) {
|
||||
Object.keys(output).forEach(function (key) {
|
||||
proxyReq.setHeader(key, output[key]);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Now, if {key:value} given, set the each header
|
||||
*
|
||||
* eg: reqHeaders: {
|
||||
* 'is-dev': 'true'
|
||||
* }
|
||||
*/
|
||||
if (Map.isMap(reqHeaders)) {
|
||||
return reqFns.concat(function (proxyReq) {
|
||||
reqHeaders.forEach(function (value, key) {
|
||||
proxyReq.setHeader(key, value);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return reqFns;
|
||||
}
|
138
node_modules/browser-sync/lib/server/proxy-utils.js
generated
vendored
Normal file
138
node_modules/browser-sync/lib/server/proxy-utils.js
generated
vendored
Normal file
@ -0,0 +1,138 @@
|
||||
var url = require("url");
|
||||
|
||||
module.exports.rewriteLinks = function (userServer) {
|
||||
|
||||
var host = userServer.hostname;
|
||||
var string = host;
|
||||
var port = userServer.port;
|
||||
|
||||
if (host && port) {
|
||||
if (parseInt(port, 10) !== 80) {
|
||||
string = host + ":" + port;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
match: new RegExp("https?:\\\\/\\\\/" + string + "|('|\")\\\/\\\/" + string + "|https?://" + string + "(\/)?|('|\")(https?://|/|\\.)?" + string + "(\/)?(.*?)(?=[ ,'\"\\s])", "g"),
|
||||
//match: new RegExp("https?:\\\\/\\\\/" + string + "|https?://" + string + "(\/)?|('|\")(https?://|/|\\.)?" + string + "(\/)?(.*?)(?=[ ,'\"\\s])", "g"),
|
||||
//match: new RegExp("https?:\\\\?/\\\\?/" + string + "(\/)?|('|\")(https?://|\\\\?/|\\.)?" + string + "(\/)?(.*?)(?=[ ,'\"\\s])", "g"),
|
||||
//match: new RegExp('https?://' + string + '(\/)?|(\'|")(https?://|/|\\.)?' + string + '(\/)?(.*?)(?=[ ,\'"\\s])', 'g'),
|
||||
//match: new RegExp("https?:\\\\/\\\\/" + string, "g"),
|
||||
fn: function (req, res, match) {
|
||||
|
||||
var proxyUrl = req.headers["host"];
|
||||
|
||||
/**
|
||||
* Reject subdomains
|
||||
*/
|
||||
if (match[0] === ".") {
|
||||
return match;
|
||||
}
|
||||
|
||||
var captured = match[0] === "'" || match[0] === "\"" ? match[0] : "";
|
||||
|
||||
/**
|
||||
* allow http https
|
||||
* @type {string}
|
||||
*/
|
||||
var pre = "//";
|
||||
|
||||
if (match[0] === "'" || match[0] === "\"") {
|
||||
match = match.slice(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* parse the url
|
||||
* @type {number|*}
|
||||
*/
|
||||
var out = url.parse(match);
|
||||
|
||||
/**
|
||||
* If host not set, just do a simple replace
|
||||
*/
|
||||
if (!out.host) {
|
||||
string = string.replace(/^(\/)/, "");
|
||||
return captured + match.replace(string, proxyUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Only add trailing slash if one was
|
||||
* present in the original match
|
||||
*/
|
||||
if (out.path === "/") {
|
||||
if (match.slice(-1) === "/") {
|
||||
out.path = "/";
|
||||
} else {
|
||||
out.path = "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finally append all of parsed url
|
||||
*/
|
||||
return [
|
||||
captured,
|
||||
pre,
|
||||
proxyUrl,
|
||||
out.path || "",
|
||||
out.hash || ""
|
||||
].join("");
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove 'domain' from any cookies
|
||||
* @param {Object} res
|
||||
*/
|
||||
module.exports.checkCookies = function checkCookies (res) {
|
||||
if (typeof(res.headers["set-cookie"]) !== "undefined") {
|
||||
res.headers["set-cookie"] = res.headers["set-cookie"].map(function (item) {
|
||||
return rewriteCookies(item);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove the domain from any cookies.
|
||||
* @param rawCookie
|
||||
* @returns {string}
|
||||
*/
|
||||
function rewriteCookies (rawCookie) {
|
||||
|
||||
var objCookie = (function () {
|
||||
// simple parse function (does not remove quotes)
|
||||
var obj = {};
|
||||
var pairs = rawCookie.split(/; */);
|
||||
|
||||
pairs.forEach( function( pair ) {
|
||||
var eqIndex = pair.indexOf("=");
|
||||
|
||||
// skip things that don't look like key=value
|
||||
if (eqIndex < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
var key = pair.substr(0, eqIndex).trim();
|
||||
obj[key] = pair.substr(eqIndex + 1, pair.length).trim();
|
||||
});
|
||||
|
||||
return obj;
|
||||
})();
|
||||
|
||||
var pairs = Object.keys(objCookie)
|
||||
.filter(function (item) {
|
||||
return item !== "domain";
|
||||
})
|
||||
.map(function (key) {
|
||||
return key + "=" + objCookie[key];
|
||||
});
|
||||
|
||||
if (rawCookie.match(/httponly/i)) {
|
||||
pairs.push("HttpOnly");
|
||||
}
|
||||
|
||||
return pairs.join("; ");
|
||||
}
|
||||
|
||||
module.exports.rewriteCookies = rewriteCookies;
|
16
node_modules/browser-sync/lib/server/snippet-server.js
generated
vendored
Normal file
16
node_modules/browser-sync/lib/server/snippet-server.js
generated
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
"use strict";
|
||||
|
||||
var connect = require("connect");
|
||||
var serverUtils = require("./utils.js");
|
||||
|
||||
/**
|
||||
* Create a server for the snippet
|
||||
* @param {BrowserSync} bs
|
||||
* @param scripts
|
||||
* @returns {*}
|
||||
*/
|
||||
module.exports = function createSnippetServer (bs, scripts) {
|
||||
|
||||
var app = serverUtils.getBaseApp(bs, bs.options, scripts);
|
||||
return serverUtils.getServer(app, bs.options);
|
||||
};
|
79
node_modules/browser-sync/lib/server/static-server.js
generated
vendored
Normal file
79
node_modules/browser-sync/lib/server/static-server.js
generated
vendored
Normal file
@ -0,0 +1,79 @@
|
||||
"use strict";
|
||||
|
||||
var connect = require("connect");
|
||||
var serverUtils = require("./utils.js");
|
||||
var resolve = require("path").resolve;
|
||||
var utils = require("../utils.js");
|
||||
var serveStatic = require("serve-static");
|
||||
var serveIndex = require("serve-index");
|
||||
|
||||
/**
|
||||
* @param {BrowserSync} bs
|
||||
* @param scripts
|
||||
* @returns {*}
|
||||
*/
|
||||
module.exports = function createServer (bs) {
|
||||
|
||||
var options = bs.options;
|
||||
var server = options.get("server");
|
||||
var basedirs = utils.arrayify(server.get("baseDir"));
|
||||
var serveStaticOptions = server.get("serveStaticOptions").toJS(); // passed to 3rd party
|
||||
|
||||
var _serveStatic = 0;
|
||||
var _routes = 0;
|
||||
bs.options = bs.options
|
||||
/**
|
||||
* Add directory Middleware if given in server.directory
|
||||
*/
|
||||
.update("middleware", function (mw) {
|
||||
if (!server.get("directory")) {
|
||||
return mw;
|
||||
}
|
||||
|
||||
return mw.concat({
|
||||
route: "",
|
||||
handle: serveIndex(resolve(basedirs[0]), {icons:true}),
|
||||
id: "Browsersync Server Directory Middleware"
|
||||
});
|
||||
})
|
||||
/**
|
||||
* Add middleware for server.baseDir Option
|
||||
*/
|
||||
.update("middleware", function (mw) {
|
||||
return mw.concat(basedirs.map(function (root) {
|
||||
return {
|
||||
route: "",
|
||||
id: "Browsersync Server ServeStatic Middleware - " + _serveStatic++,
|
||||
handle: serveStatic(resolve(root), serveStaticOptions)
|
||||
}
|
||||
}));
|
||||
})
|
||||
/**
|
||||
* Add middleware for server.routes
|
||||
*/
|
||||
.update("middleware", function (mw) {
|
||||
|
||||
if (!server.get("routes")) {
|
||||
return mw;
|
||||
}
|
||||
|
||||
return mw.concat(server.get("routes").map(function (root, urlPath) {
|
||||
// strip trailing slash
|
||||
if (urlPath[urlPath.length - 1] === "/") {
|
||||
urlPath = urlPath.slice(0, -1);
|
||||
}
|
||||
return {
|
||||
route: urlPath,
|
||||
id: "Browsersync Server Routes Middleware - " + _routes++,
|
||||
handle: serveStatic(resolve(root))
|
||||
}
|
||||
}));
|
||||
});
|
||||
|
||||
var app = serverUtils.getBaseApp(bs);
|
||||
|
||||
/**
|
||||
* Finally, return the server + App
|
||||
*/
|
||||
return serverUtils.getServer(app, bs.options);
|
||||
};
|
453
node_modules/browser-sync/lib/server/utils.js
generated
vendored
Normal file
453
node_modules/browser-sync/lib/server/utils.js
generated
vendored
Normal file
@ -0,0 +1,453 @@
|
||||
"use strict";
|
||||
|
||||
var fs = require("fs");
|
||||
var path = require("path");
|
||||
var join = require("path").join;
|
||||
var connect = require("connect");
|
||||
var Immutable = require("immutable");
|
||||
var http = require("http");
|
||||
var https = require("https");
|
||||
var Map = require("immutable").Map;
|
||||
var fromJS = require("immutable").fromJS;
|
||||
var List = require("immutable").List;
|
||||
var snippet = require("./../snippet").utils;
|
||||
var _ = require("./../../lodash.custom");
|
||||
var serveStatic = require("serve-static");
|
||||
var logger = require("../logger");
|
||||
var snippetUtils = require("../snippet").utils;
|
||||
var lrSnippet = require("resp-modifier");
|
||||
var utils = require("../utils");
|
||||
|
||||
function getCa (options) {
|
||||
var caOption = options.getIn(["https", "ca"]);
|
||||
// if not provided, use Browsersync self-signed
|
||||
if (typeof caOption === "undefined") {
|
||||
return fs.readFileSync(join(__dirname, "certs", "server.csr"));
|
||||
}
|
||||
// if a string was given, read that file from disk
|
||||
if (typeof caOption === "string") {
|
||||
return fs.readFileSync(caOption);
|
||||
}
|
||||
// if an array was given, read all
|
||||
if (List.isList(caOption)) {
|
||||
return caOption.toArray().map(function (x) {
|
||||
return fs.readFileSync(x);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function getKey(options) {
|
||||
return fs.readFileSync(options.getIn(["https", "key"]) || join(__dirname, "certs", "server.key"));
|
||||
}
|
||||
|
||||
function getCert(options) {
|
||||
return fs.readFileSync(options.getIn(["https", "cert"]) || join(__dirname, "certs", "server.crt"));
|
||||
}
|
||||
|
||||
function getHttpsServerDefaults (options) {
|
||||
return fromJS({
|
||||
key: getKey(options),
|
||||
cert: getCert(options),
|
||||
ca: getCa(options),
|
||||
passphrase: ""
|
||||
});
|
||||
}
|
||||
|
||||
function getPFXDefaults (options) {
|
||||
return fromJS({
|
||||
pfx: fs.readFileSync(options.getIn(["https", "pfx"]))
|
||||
});
|
||||
}
|
||||
|
||||
var serverUtils = {
|
||||
/**
|
||||
* @param options
|
||||
* @returns {{key, cert}}
|
||||
*/
|
||||
getHttpsOptions: function (options) {
|
||||
var userOption = options.get("https");
|
||||
if (Map.isMap(userOption)) {
|
||||
if (userOption.has("pfx")) {
|
||||
return userOption.mergeDeep(getPFXDefaults(options));
|
||||
}
|
||||
return userOption.mergeDeep(getHttpsServerDefaults(options));
|
||||
}
|
||||
return getHttpsServerDefaults(options);
|
||||
},
|
||||
/**
|
||||
* Get either http or https server
|
||||
* or use the httpModule provided in options if present
|
||||
*/
|
||||
getServer: function (app, options) {
|
||||
return {
|
||||
server: (function () {
|
||||
|
||||
var httpModule = serverUtils.getHttpModule(options);
|
||||
|
||||
if (options.get("scheme") === "https") {
|
||||
var opts = serverUtils.getHttpsOptions(options);
|
||||
return httpModule.createServer(opts.toJS(), app);
|
||||
}
|
||||
|
||||
return httpModule.createServer(app);
|
||||
})(),
|
||||
app: app
|
||||
};
|
||||
},
|
||||
getHttpModule: function (options) {
|
||||
/**
|
||||
* Users may provide a string to be used by nodes
|
||||
* require lookup.
|
||||
*/
|
||||
var httpModule = options.get("httpModule");
|
||||
|
||||
if (typeof httpModule === "string") {
|
||||
/**
|
||||
* Note, this could throw, but let that happen as
|
||||
* the error message good enough.
|
||||
*/
|
||||
var maybe = path.resolve(process.cwd(), "node_modules", httpModule);
|
||||
return require(maybe);
|
||||
}
|
||||
|
||||
if (options.get("scheme") === "https") {
|
||||
return https;
|
||||
}
|
||||
|
||||
return http;
|
||||
},
|
||||
getMiddlewares: function (bs) {
|
||||
|
||||
var clientJs = bs.pluginManager.hook("client:js", {
|
||||
port: bs.options.get("port"),
|
||||
options: bs.options
|
||||
});
|
||||
|
||||
var scripts = bs.pluginManager.get("client:script")(
|
||||
bs.options.toJS(),
|
||||
clientJs,
|
||||
"middleware"
|
||||
);
|
||||
|
||||
var defaultMiddlewares = [
|
||||
{
|
||||
id: "Browsersync HTTP Protocol",
|
||||
route: require("../config").httpProtocol.path,
|
||||
handle: require("../http-protocol").middleware(bs)
|
||||
},
|
||||
{
|
||||
id: "Browsersync IE8 Support",
|
||||
route: "",
|
||||
handle: snippet.isOldIe(bs.options.get("excludedFileTypes").toJS())
|
||||
},
|
||||
{
|
||||
id: "Browsersync Response Modifier",
|
||||
route: "",
|
||||
handle: serverUtils.getSnippetMiddleware(bs)
|
||||
},
|
||||
{
|
||||
id: "Browsersync Client - versioned",
|
||||
route: bs.options.getIn(["scriptPaths", "versioned"]),
|
||||
handle: scripts
|
||||
},
|
||||
{
|
||||
id: "Browsersync Client",
|
||||
route: bs.options.getIn(["scriptPaths", "path"]),
|
||||
handle: scripts
|
||||
}
|
||||
];
|
||||
|
||||
/**
|
||||
* Add cors middleware to the front of the stack
|
||||
* if a user provided a 'cors' flag
|
||||
*/
|
||||
if (bs.options.get("cors")) {
|
||||
defaultMiddlewares.unshift({
|
||||
id: "Browsersync CORS support",
|
||||
route: "",
|
||||
handle: serverUtils.getCorsMiddlewware()
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Add serve static middleware
|
||||
*/
|
||||
if (bs.options.get("serveStatic")) {
|
||||
|
||||
var ssMiddlewares = serverUtils.getServeStaticMiddlewares(bs.options.get("serveStatic"), bs.options.get("serveStaticOptions", Immutable.Map({})).toJS());
|
||||
var withErrors = ssMiddlewares.filter(function(x) { return x.get("errors").size > 0 });
|
||||
var withoutErrors = ssMiddlewares.filter(function(x) { return x.get("errors").size === 0 });
|
||||
|
||||
if (withErrors.size) {
|
||||
withErrors.forEach(function (item) {
|
||||
logger.logger.error("{red:Warning!} %s", item.getIn(["errors", 0, "data", "message"]));
|
||||
});
|
||||
}
|
||||
|
||||
if (withoutErrors.size) {
|
||||
withoutErrors.forEach(function (item) {
|
||||
defaultMiddlewares.push.apply(defaultMiddlewares, item.get("items").toJS());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add user-provided middlewares
|
||||
*/
|
||||
var userMiddlewares = bs.options.get("middleware").map(normaliseMiddleware).toArray();
|
||||
var beforeMiddlewares = userMiddlewares.filter(function (x) { return x.override; });
|
||||
var afterMiddlewares = userMiddlewares.filter(function (x) { return !x.override; });
|
||||
|
||||
return [].concat(beforeMiddlewares, defaultMiddlewares, afterMiddlewares);
|
||||
|
||||
function normaliseMiddleware(item) {
|
||||
/**
|
||||
* Object given in options, which
|
||||
* ended up being a Map
|
||||
*/
|
||||
if (Map.isMap(item)) {
|
||||
return item.toJS();
|
||||
}
|
||||
/**
|
||||
* Single function
|
||||
*/
|
||||
if (typeof item === "function") {
|
||||
return {
|
||||
route: "",
|
||||
handle: item
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Plain obj
|
||||
*/
|
||||
if ((item.route !== undefined) && item.handle) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
},
|
||||
getBaseApp: function (bs) {
|
||||
|
||||
var app = connect();
|
||||
var middlewares = serverUtils.getMiddlewares(bs);
|
||||
|
||||
/**
|
||||
* Add all internal middlewares
|
||||
*/
|
||||
middlewares.forEach(function (item) {
|
||||
app.stack.push(item);
|
||||
});
|
||||
|
||||
return app;
|
||||
},
|
||||
getSnippetMiddleware: function (bs) {
|
||||
|
||||
var rules = [];
|
||||
var blacklist = List([])
|
||||
.concat(bs.options.getIn(["snippetOptions", "ignorePaths"]))
|
||||
.concat(bs.options.getIn(["snippetOptions", "blacklist"]))
|
||||
.filter(Boolean);
|
||||
|
||||
var whitelist = List([])
|
||||
.concat(bs.options.getIn(["snippetOptions", "whitelist"]));
|
||||
|
||||
// Snippet
|
||||
rules.push(snippetUtils.getRegex(bs.options.get("snippet"), bs.options.get("snippetOptions")));
|
||||
|
||||
// User
|
||||
bs.options.get("rewriteRules").forEach(function (rule) {
|
||||
if (Map.isMap(rule)) {
|
||||
rules.push(rule.toJS());
|
||||
}
|
||||
if (_.isPlainObject(rule)) {
|
||||
rules.push(rule);
|
||||
}
|
||||
});
|
||||
|
||||
// Proxy
|
||||
if (bs.options.get("proxy")) {
|
||||
var proxyRule = require("./proxy-utils").rewriteLinks(bs.options.getIn(["proxy", "url"]).toJS());
|
||||
rules.push(proxyRule);
|
||||
}
|
||||
|
||||
var lr = lrSnippet.create({
|
||||
rules: rules,
|
||||
blacklist: blacklist.toArray(),
|
||||
whitelist: whitelist.toArray()
|
||||
});
|
||||
|
||||
return lr.middleware;
|
||||
},
|
||||
getCorsMiddlewware: function () {
|
||||
|
||||
return function (req, res, next) {
|
||||
// Website you wish to allow to connect
|
||||
res.setHeader("Access-Control-Allow-Origin", "*");
|
||||
|
||||
// Request methods you wish to allow
|
||||
res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS, PUT, PATCH, DELETE");
|
||||
|
||||
// Request headers you wish to allow
|
||||
res.setHeader("Access-Control-Allow-Headers", "X-Requested-With,content-type");
|
||||
|
||||
// Set to true if you need the website to include cookies in the requests sent
|
||||
// to the API (e.g. in case you use sessions)
|
||||
res.setHeader("Access-Control-Allow-Credentials", true);
|
||||
next();
|
||||
}
|
||||
},
|
||||
/**
|
||||
* @param ssOption
|
||||
* @param serveStaticOptions
|
||||
* @returns {*}
|
||||
*/
|
||||
getServeStaticMiddlewares: function (ssOption, serveStaticOptions) {
|
||||
|
||||
return ssOption.map(function (dir, i) {
|
||||
|
||||
/**
|
||||
* When a user gives a plain string only, eg:
|
||||
* serveStatic: ['./temp']
|
||||
* ->
|
||||
* This means a middleware will be created with
|
||||
* route: ''
|
||||
* handle: serveStatic('./temp', options)
|
||||
*/
|
||||
if (_.isString(dir)) {
|
||||
return getFromString(dir)
|
||||
}
|
||||
|
||||
/**
|
||||
* If a user gave an object eg:
|
||||
* serveStatic: [{route: "", dir: ["test", "./tmp"]}]
|
||||
* ->
|
||||
* This means we need to create a middle for each route + dir combo
|
||||
*/
|
||||
if (Immutable.Map.isMap(dir)) {
|
||||
return getFromMap(dir, i);
|
||||
}
|
||||
|
||||
/**
|
||||
* At this point, an item in the serveStatic array was not a string
|
||||
* or an object so we return an error that can be logged
|
||||
*/
|
||||
return fromJS({
|
||||
items: [],
|
||||
errors: [{
|
||||
type: "Invalid Type",
|
||||
data: {
|
||||
message: "Only strings and Objects (with route+dir) are supported for the ServeStatic option"
|
||||
}
|
||||
}]
|
||||
})
|
||||
});
|
||||
|
||||
/**
|
||||
* @param {string} x
|
||||
* @returns {string}
|
||||
*/
|
||||
function getRoute (x) {
|
||||
if (x === "") return "";
|
||||
return x[0] === "/" ? x : "/" + x;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dir
|
||||
* @returns {Map}
|
||||
*/
|
||||
function getFromString(dir) {
|
||||
return fromJS({
|
||||
items: [
|
||||
{
|
||||
route: "",
|
||||
handle: serveStatic(dir, serveStaticOptions)
|
||||
}
|
||||
],
|
||||
errors: []
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dir
|
||||
* @returns {Map}
|
||||
*/
|
||||
function getFromMap(dir) {
|
||||
|
||||
var ssOptions = (function () {
|
||||
if (dir.get("options")) {
|
||||
return dir.get("options").toJS();
|
||||
}
|
||||
return {}
|
||||
})();
|
||||
|
||||
var route = Immutable.List([]).concat(dir.get("route")).filter(_.isString);
|
||||
var _dir = Immutable.List([]).concat(dir.get("dir")).filter(_.isString);
|
||||
|
||||
if (_dir.size === 0) {
|
||||
|
||||
return fromJS({
|
||||
items: [],
|
||||
errors: [{
|
||||
type: "Invalid Object",
|
||||
data: {
|
||||
message: "Serve Static requires a 'dir' property when using an Object"
|
||||
}
|
||||
}]
|
||||
})
|
||||
}
|
||||
|
||||
var ssItems = (function () {
|
||||
|
||||
/**
|
||||
* iterate over every 'route' item
|
||||
* @type {Immutable.List<any>|Immutable.List<*>|Immutable.List<any>|*}
|
||||
*/
|
||||
var routeItems = (function () {
|
||||
|
||||
/**
|
||||
* If no 'route' was given, assume we want to match all
|
||||
* paths
|
||||
*/
|
||||
if (route.size === 0) {
|
||||
return _dir.map(function (dirString) {
|
||||
return Map({
|
||||
route: "",
|
||||
dir: dirString
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return route.reduce(function (acc, routeString) {
|
||||
/**
|
||||
* For each 'route' item, also iterate through 'dirs'
|
||||
* @type {Immutable.Iterable<K, M>}
|
||||
*/
|
||||
var perDir = _dir.map(function (dirString) {
|
||||
return Map({
|
||||
route: getRoute(routeString),
|
||||
dir: dirString
|
||||
})
|
||||
});
|
||||
return acc.concat(perDir);
|
||||
|
||||
}, List([]));
|
||||
})();
|
||||
|
||||
/**
|
||||
* Now create a serverStatic Middleware for each item
|
||||
*/
|
||||
return routeItems.map(function (routeItem) {
|
||||
return routeItem.merge({
|
||||
handle: serveStatic(routeItem.get("dir"), ssOptions)
|
||||
});
|
||||
});
|
||||
})();
|
||||
|
||||
return fromJS({
|
||||
items: ssItems,
|
||||
errors: []
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = serverUtils;
|
Reference in New Issue
Block a user