localhostify
Advanced tools
Comparing version 0.1.1 to 0.2.0
@@ -1,1 +0,1 @@ | ||
var e=require("util"),t=require("url"),r=require("http"),o=require("https"),n=require("stream"),s=require("assert");function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=/*#__PURE__*/i(e),c=/*#__PURE__*/i(t),u=/*#__PURE__*/i(r),h=/*#__PURE__*/i(o),f=/*#__PURE__*/i(n),l=/*#__PURE__*/i(s);function p(){return p=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o])}return e},p.apply(this,arguments)}function d(e){var t={exports:{}};return e(t,t.exports),t.exports}var g=d(function(e){var t=Object.prototype.hasOwnProperty,r="~";function o(){}function n(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function s(e,t,o,s,i){if("function"!=typeof o)throw new TypeError("The listener must be a function");var a=new n(o,s||e,i),c=r?r+t:t;return e._events[c]?e._events[c].fn?e._events[c]=[e._events[c],a]:e._events[c].push(a):(e._events[c]=a,e._eventsCount++),e}function i(e,t){0==--e._eventsCount?e._events=new o:delete e._events[t]}function a(){this._events=new o,this._eventsCount=0}Object.create&&(o.prototype=Object.create(null),(new o).__proto__||(r=!1)),a.prototype.eventNames=function(){var e,o,n=[];if(0===this._eventsCount)return n;for(o in e=this._events)t.call(e,o)&&n.push(r?o.slice(1):o);return Object.getOwnPropertySymbols?n.concat(Object.getOwnPropertySymbols(e)):n},a.prototype.listeners=function(e){var t=this._events[r?r+e:e];if(!t)return[];if(t.fn)return[t.fn];for(var o=0,n=t.length,s=new Array(n);o<n;o++)s[o]=t[o].fn;return s},a.prototype.listenerCount=function(e){var t=this._events[r?r+e:e];return t?t.fn?1:t.length:0},a.prototype.emit=function(e,t,o,n,s,i){var a=r?r+e:e;if(!this._events[a])return!1;var c,u,h=this._events[a],f=arguments.length;if(h.fn){switch(h.once&&this.removeListener(e,h.fn,void 0,!0),f){case 1:return h.fn.call(h.context),!0;case 2:return h.fn.call(h.context,t),!0;case 3:return h.fn.call(h.context,t,o),!0;case 4:return h.fn.call(h.context,t,o,n),!0;case 5:return h.fn.call(h.context,t,o,n,s),!0;case 6:return h.fn.call(h.context,t,o,n,s,i),!0}for(u=1,c=new Array(f-1);u<f;u++)c[u-1]=arguments[u];h.fn.apply(h.context,c)}else{var l,p=h.length;for(u=0;u<p;u++)switch(h[u].once&&this.removeListener(e,h[u].fn,void 0,!0),f){case 1:h[u].fn.call(h[u].context);break;case 2:h[u].fn.call(h[u].context,t);break;case 3:h[u].fn.call(h[u].context,t,o);break;case 4:h[u].fn.call(h[u].context,t,o,n);break;default:if(!c)for(l=1,c=new Array(f-1);l<f;l++)c[l-1]=arguments[l];h[u].fn.apply(h[u].context,c)}}return!0},a.prototype.on=function(e,t,r){return s(this,e,t,r,!1)},a.prototype.once=function(e,t,r){return s(this,e,t,r,!0)},a.prototype.removeListener=function(e,t,o,n){var s=r?r+e:e;if(!this._events[s])return this;if(!t)return i(this,s),this;var a=this._events[s];if(a.fn)a.fn!==t||n&&!a.once||o&&a.context!==o||i(this,s);else{for(var c=0,u=[],h=a.length;c<h;c++)(a[c].fn!==t||n&&!a[c].once||o&&a[c].context!==o)&&u.push(a[c]);u.length?this._events[s]=1===u.length?u[0]:u:i(this,s)}return this},a.prototype.removeAllListeners=function(e){var t;return e?this._events[t=r?r+e:e]&&i(this,t):(this._events=new o,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=r,a.EventEmitter=a,e.exports=a}),m=d(function(e,t){var r=t,o=a.default._extend,n=/(^|,)\s*upgrade\s*($|,)/i,s=/^https|wss/;r.isSSL=s,r.setupOutgoing=function(e,t,i,a){e.port=t[a||"target"].port||(s.test(t[a||"target"].protocol)?443:80),["host","hostname","socketPath","pfx","key","passphrase","cert","ca","ciphers","secureProtocol"].forEach(function(r){e[r]=t[a||"target"][r]}),e.method=t.method||i.method,e.headers=o({},i.headers),t.headers&&o(e.headers,t.headers),t.auth&&(e.auth=t.auth),t.ca&&(e.ca=t.ca),s.test(t[a||"target"].protocol)&&(e.rejectUnauthorized=void 0===t.secure||t.secure),e.agent=t.agent||!1,e.localAddress=t.localAddress,e.agent||(e.headers=e.headers||{},"string"==typeof e.headers.connection&&n.test(e.headers.connection)||(e.headers.connection="close"));var u=t[a||"target"],h=u&&!1!==t.prependPath&&u.path||"",f=t.toProxy?i.url:c.default.parse(i.url).path||"";return e.path=r.urlJoin(h,f=t.ignorePath?"":f),t.changeOrigin&&(e.headers.host=function(e,t){if(t=t.split(":")[0],!(e=+e))return!1;switch(t){case"http":case"ws":return 80!==e;case"https":case"wss":return 443!==e;case"ftp":return 21!==e;case"gopher":return 70!==e;case"file":return!1}return 0!==e}(e.port,t[a||"target"].protocol)&&!~e.host.indexOf(":")?e.host+":"+e.port:e.host),e},r.setupSocket=function(e){return e.setTimeout(0),e.setNoDelay(!0),e.setKeepAlive(!0,0),e},r.getPort=function(e){var t=e.headers.host?e.headers.host.match(/:(\d+)/):"";return t?t[1]:r.hasEncryptedConnection(e)?"443":"80"},r.hasEncryptedConnection=function(e){return Boolean(e.connection.encrypted||e.connection.pair)},r.urlJoin=function(){var e,t=Array.prototype.slice.call(arguments),r=t.length-1,o=t[r],n=o.split("?");return t[r]=n.shift(),(e=[t.filter(Boolean).join("/").replace(/\/+/g,"/").replace("http:/","http://").replace("https:/","https://")]).push.apply(e,n),e.join("?")},r.rewriteCookieProperty=function e(t,r,o){return Array.isArray(t)?t.map(function(t){return e(t,r,o)}):t.replace(new RegExp("(;\\s*"+o+"=)([^;]+)","i"),function(e,t,o){var n;if(o in r)n=r[o];else{if(!("*"in r))return e;n=r["*"]}return n?t+n:""})}}),w=/^201|30(1|2|7|8)$/,v={removeChunked:function(e,t,r){"1.0"===e.httpVersion&&delete r.headers["transfer-encoding"]},setConnection:function(e,t,r){"1.0"===e.httpVersion?r.headers.connection=e.headers.connection||"close":"2.0"===e.httpVersion||r.headers.connection||(r.headers.connection=e.headers.connection||"keep-alive")},setRedirectHostRewrite:function(e,t,r,o){if((o.hostRewrite||o.autoRewrite||o.protocolRewrite)&&r.headers.location&&w.test(r.statusCode)){var n=c.default.parse(o.target),s=c.default.parse(r.headers.location);if(n.host!=s.host)return;o.hostRewrite?s.host=o.hostRewrite:o.autoRewrite&&(s.host=e.headers.host),o.protocolRewrite&&(s.protocol=o.protocolRewrite),r.headers.location=s.format()}},writeHeaders:function(e,t,r,o){var n,s=o.cookieDomainRewrite,i=o.cookiePathRewrite,a=o.preserveHeaderKeyCase;if("string"==typeof s&&(s={"*":s}),"string"==typeof i&&(i={"*":i}),a&&null!=r.rawHeaders){n={};for(var c=0;c<r.rawHeaders.length;c+=2){var u=r.rawHeaders[c];n[u.toLowerCase()]=u}}Object.keys(r.headers).forEach(function(e){var o=r.headers[e];a&&n&&(e=n[e]||e),function(e,r){null!=r&&(s&&"set-cookie"===e.toLowerCase()&&(r=m.rewriteCookieProperty(r,s,"domain")),i&&"set-cookie"===e.toLowerCase()&&(r=m.rewriteCookieProperty(r,i,"path")),t.setHeader(String(e).trim(),r))}(e,o)})},writeStatusCode:function(e,t,r){r.statusMessage?(t.statusCode=r.statusCode,t.statusMessage=r.statusMessage):t.statusCode=r.statusCode}},y=1e3,C=60*y,_=60*C,b=24*_,R=function(e,t){t=t||{};var r=typeof e;if("string"===r&&e.length>0)return function(e){if(!((e=String(e)).length>100)){var t=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(t){var r=parseFloat(t[1]);switch((t[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return 315576e5*r;case"weeks":case"week":case"w":return 6048e5*r;case"days":case"day":case"d":return r*b;case"hours":case"hour":case"hrs":case"hr":case"h":return r*_;case"minutes":case"minute":case"mins":case"min":case"m":return r*C;case"seconds":case"second":case"secs":case"sec":case"s":return r*y;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return r;default:return}}}}(e);if("number"===r&&isFinite(e))return t.long?function(e){var t=Math.abs(e);return t>=b?E(e,t,b,"day"):t>=_?E(e,t,_,"hour"):t>=C?E(e,t,C,"minute"):t>=y?E(e,t,y,"second"):e+" ms"}(e):function(e){var t=Math.abs(e);return t>=b?Math.round(e/b)+"d":t>=_?Math.round(e/_)+"h":t>=C?Math.round(e/C)+"m":t>=y?Math.round(e/y)+"s":e+"ms"}(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))};function E(e,t,r,o){var n=t>=1.5*r;return Math.round(e/r)+" "+o+(n?"s":"")}var x,F=d(function(e,t){t.formatArgs=function(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const r="color: "+this.color;t.splice(1,0,r,"color: inherit");let o=0,n=0;t[0].replace(/%[a-zA-Z%]/g,e=>{"%%"!==e&&(o++,"%c"===e&&(n=o))}),t.splice(n,0,r)},t.save=function(e){try{e?t.storage.setItem("debug",e):t.storage.removeItem("debug")}catch(e){}},t.load=function(){let e;try{e=t.storage.getItem("debug")}catch(e){}return!e&&"undefined"!=typeof process&&"env"in process&&(e=process.env.DEBUG),e},t.useColors=function(){return!("undefined"==typeof window||!window.process||"renderer"!==window.process.type&&!window.process.__nwjs)||("undefined"==typeof navigator||!navigator.userAgent||!navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))&&("undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/))},t.storage=function(){try{return localStorage}catch(e){}}(),t.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],t.log=console.debug||console.log||(()=>{}),e.exports=function(e){function t(e){let o,n,s,i=null;function a(...e){if(!a.enabled)return;const r=a,n=Number(new Date);r.diff=n-(o||n),r.prev=o,r.curr=n,o=n,e[0]=t.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let s=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,(o,n)=>{if("%%"===o)return"%";s++;const i=t.formatters[n];return"function"==typeof i&&(o=i.call(r,e[s]),e.splice(s,1),s--),o}),t.formatArgs.call(r,e),(r.log||t.log).apply(r,e)}return a.namespace=e,a.useColors=t.useColors(),a.color=t.selectColor(e),a.extend=r,a.destroy=t.destroy,Object.defineProperty(a,"enabled",{enumerable:!0,configurable:!1,get:()=>null!==i?i:(n!==t.namespaces&&(n=t.namespaces,s=t.enabled(e)),s),set:e=>{i=e}}),"function"==typeof t.init&&t.init(a),a}function r(e,r){const o=t(this.namespace+(void 0===r?":":r)+e);return o.log=this.log,o}function o(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return t.debug=t,t.default=t,t.coerce=function(e){return e instanceof Error?e.stack||e.message:e},t.disable=function(){const e=[...t.names.map(o),...t.skips.map(o).map(e=>"-"+e)].join(",");return t.enable(""),e},t.enable=function(e){let r;t.save(e),t.namespaces=e,t.names=[],t.skips=[];const o=("string"==typeof e?e:"").split(/[\s,]+/),n=o.length;for(r=0;r<n;r++)o[r]&&("-"===(e=o[r].replace(/\*/g,".*?"))[0]?t.skips.push(new RegExp("^"+e.substr(1)+"$")):t.names.push(new RegExp("^"+e+"$")))},t.enabled=function(e){if("*"===e[e.length-1])return!0;let r,o;for(r=0,o=t.skips.length;r<o;r++)if(t.skips[r].test(e))return!1;for(r=0,o=t.names.length;r<o;r++)if(t.names[r].test(e))return!0;return!1},t.humanize=R,t.destroy=function(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")},Object.keys(e).forEach(r=>{t[r]=e[r]}),t.names=[],t.skips=[],t.formatters={},t.selectColor=function(e){let r=0;for(let t=0;t<e.length;t++)r=(r<<5)-r+e.charCodeAt(t),r|=0;return t.colors[Math.abs(r)%t.colors.length]},t.enable(t.load()),t}(t);const{formatters:r}=e.exports;r.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}}),k=function(){if(!x){try{x=F("follow-redirects")}catch(e){}"function"!=typeof x&&(x=function(){})}x.apply(null,arguments)},O=c.default.URL,q=f.default.Writable,A=["abort","aborted","connect","error","socket","timeout"],P=Object.create(null);A.forEach(function(e){P[e]=function(t,r,o){this._redirectable.emit(e,t,r,o)}});var S=D("ERR_FR_REDIRECTION_FAILURE",""),T=D("ERR_FR_TOO_MANY_REDIRECTS","Maximum number of redirects exceeded"),L=D("ERR_FR_MAX_BODY_LENGTH_EXCEEDED","Request body larger than maxBodyLength limit"),j=D("ERR_STREAM_WRITE_AFTER_END","write after end");function H(e,t){q.call(this),this._sanitizeOptions(e),this._options=e,this._ended=!1,this._ending=!1,this._redirectCount=0,this._redirects=[],this._requestBodyLength=0,this._requestBodyBuffers=[],t&&this.on("response",t);var r=this;this._onNativeResponse=function(e){r._processResponse(e)},this._performRequest()}function B(e){var t={maxRedirects:21,maxBodyLength:10485760},r={};return Object.keys(e).forEach(function(o){var n=o+":",s=r[n]=e[o],i=t[o]=Object.create(s);Object.defineProperties(i,{request:{value:function(e,o,s){if("string"==typeof e){var i=e;try{e=M(new O(i))}catch(t){e=c.default.parse(i)}}else O&&e instanceof O?e=M(e):(s=o,o=e,e={protocol:n});return"function"==typeof o&&(s=o,o=null),(o=Object.assign({maxRedirects:t.maxRedirects,maxBodyLength:t.maxBodyLength},e,o)).nativeProtocols=r,l.default.equal(o.protocol,n,"protocol mismatch"),k("options",o),new H(o,s)},configurable:!0,enumerable:!0,writable:!0},get:{value:function(e,t,r){var o=i.request(e,t,r);return o.end(),o},configurable:!0,enumerable:!0,writable:!0}})}),t}function N(){}function M(e){var t={protocol:e.protocol,hostname:e.hostname.startsWith("[")?e.hostname.slice(1,-1):e.hostname,hash:e.hash,search:e.search,pathname:e.pathname,path:e.pathname+e.search,href:e.href};return""!==e.port&&(t.port=Number(e.port)),t}function U(e,t){var r;for(var o in t)e.test(o)&&(r=t[o],delete t[o]);return r}function D(e,t){function r(e){Error.captureStackTrace(this,this.constructor),this.message=e||t}return(r.prototype=new Error).constructor=r,r.prototype.name="Error ["+e+"]",r.prototype.code=e,r}function I(e){for(var t=0;t<A.length;t++)e.removeListener(A[t],P[A[t]]);e.on("error",N),e.abort()}(H.prototype=Object.create(q.prototype)).abort=function(){I(this._currentRequest),this.emit("abort")},H.prototype.write=function(e,t,r){if(this._ending)throw new j;if(!("string"==typeof e||"object"==typeof e&&"length"in e))throw new TypeError("data should be a string, Buffer or Uint8Array");"function"==typeof t&&(r=t,t=null),0!==e.length?this._requestBodyLength+e.length<=this._options.maxBodyLength?(this._requestBodyLength+=e.length,this._requestBodyBuffers.push({data:e,encoding:t}),this._currentRequest.write(e,t,r)):(this.emit("error",new L),this.abort()):r&&r()},H.prototype.end=function(e,t,r){if("function"==typeof e?(r=e,e=t=null):"function"==typeof t&&(r=t,t=null),e){var o=this,n=this._currentRequest;this.write(e,t,function(){o._ended=!0,n.end(null,null,r)}),this._ending=!0}else this._ended=this._ending=!0,this._currentRequest.end(null,null,r)},H.prototype.setHeader=function(e,t){this._options.headers[e]=t,this._currentRequest.setHeader(e,t)},H.prototype.removeHeader=function(e){delete this._options.headers[e],this._currentRequest.removeHeader(e)},H.prototype.setTimeout=function(e,t){var r=this;function o(t){t.setTimeout(e),t.removeListener("timeout",t.destroy),t.addListener("timeout",t.destroy)}function n(t){r._timeout&&clearTimeout(r._timeout),r._timeout=setTimeout(function(){r.emit("timeout"),s()},e),o(t)}function s(){r._timeout&&(clearTimeout(r._timeout),r._timeout=null),t&&r.removeListener("timeout",t),r.socket||r._currentRequest.removeListener("socket",n)}return t&&this.on("timeout",t),this.socket?n(this.socket):this._currentRequest.once("socket",n),this.on("socket",o),this.once("response",s),this.once("error",s),this},["flushHeaders","getHeader","setNoDelay","setSocketKeepAlive"].forEach(function(e){H.prototype[e]=function(t,r){return this._currentRequest[e](t,r)}}),["aborted","connection","socket"].forEach(function(e){Object.defineProperty(H.prototype,e,{get:function(){return this._currentRequest[e]}})}),H.prototype._sanitizeOptions=function(e){if(e.headers||(e.headers={}),e.host&&(e.hostname||(e.hostname=e.host),delete e.host),!e.pathname&&e.path){var t=e.path.indexOf("?");t<0?e.pathname=e.path:(e.pathname=e.path.substring(0,t),e.search=e.path.substring(t))}},H.prototype._performRequest=function(){var e=this._options.protocol,t=this._options.nativeProtocols[e];if(t){if(this._options.agents){var r=e.substr(0,e.length-1);this._options.agent=this._options.agents[r]}var o=this._currentRequest=t.request(this._options,this._onNativeResponse);this._currentUrl=c.default.format(this._options),o._redirectable=this;for(var n=0;n<A.length;n++)o.on(A[n],P[A[n]]);if(this._isRedirect){var s=0,i=this,a=this._requestBodyBuffers;!function e(t){if(o===i._currentRequest)if(t)i.emit("error",t);else if(s<a.length){var r=a[s++];o.finished||o.write(r.data,r.encoding,e)}else i._ended&&o.end()}()}}else this.emit("error",new TypeError("Unsupported protocol "+e))},H.prototype._processResponse=function(e){var t=e.statusCode;this._options.trackRedirects&&this._redirects.push({url:this._currentUrl,headers:e.headers,statusCode:t});var r=e.headers.location;if(r&&!1!==this._options.followRedirects&&t>=300&&t<400){if(I(this._currentRequest),e.destroy(),++this._redirectCount>this._options.maxRedirects)return void this.emit("error",new T);((301===t||302===t)&&"POST"===this._options.method||303===t&&!/^(?:GET|HEAD)$/.test(this._options.method))&&(this._options.method="GET",this._requestBodyBuffers=[],U(/^content-/i,this._options.headers));var o=U(/^host$/i,this._options.headers)||c.default.parse(this._currentUrl).hostname,n=c.default.resolve(this._currentUrl,r);k("redirecting to",n),this._isRedirect=!0;var s=c.default.parse(n);if(Object.assign(this._options,s),s.hostname!==o&&U(/^authorization$/i,this._options.headers),"function"==typeof this._options.beforeRedirect){var i={headers:e.headers};try{this._options.beforeRedirect.call(null,this._options,i)}catch(e){return void this.emit("error",e)}this._sanitizeOptions(this._options)}try{this._performRequest()}catch(e){var a=new S("Redirected request failed: "+e.message);a.cause=e,this.emit("error",a)}}else e.responseUrl=this._currentUrl,e.redirects=this._redirects,this.emit("response",e),this._requestBodyBuffers=[]};var $=B({http:u.default,https:h.default});$.wrap=B;var z=v;z=Object.keys(z).map(function(e){return z[e]});var W={http:u.default,https:h.default},G={deleteLength:function(e,t,r){"DELETE"!==e.method&&"OPTIONS"!==e.method||e.headers["content-length"]||(e.headers["content-length"]="0",delete e.headers["transfer-encoding"])},timeout:function(e,t,r){r.timeout&&e.socket.setTimeout(r.timeout)},XHeaders:function(e,t,r){if(r.xfwd){var o=e.isSpdy||m.hasEncryptedConnection(e),n={for:e.connection.remoteAddress||e.socket.remoteAddress,port:m.getPort(e),proto:o?"https":"http"};["for","port","proto"].forEach(function(t){e.headers["x-forwarded-"+t]=(e.headers["x-forwarded-"+t]||"")+(e.headers["x-forwarded-"+t]?",":"")+n[t]}),e.headers["x-forwarded-host"]=e.headers["x-forwarded-host"]||e.headers.host||""}},stream:function(e,t,r,o,n,s){n.emit("start",e,t,r.target||r.forward);var i=r.followRedirects?$:W,a=i.http,c=i.https;if(r.forward){var u=("https:"===r.forward.protocol?c:a).request(m.setupOutgoing(r.ssl||{},r,e,"forward")),h=p(u,r.forward);if(e.on("error",h),u.on("error",h),(r.buffer||e).pipe(u),!r.target)return t.end()}var f=("https:"===r.target.protocol?c:a).request(m.setupOutgoing(r.ssl||{},r,e));f.on("socket",function(o){n&&!f.getHeader("expect")&&n.emit("proxyReq",f,e,t,r)}),r.proxyTimeout&&f.setTimeout(r.proxyTimeout,function(){f.abort()}),e.on("aborted",function(){f.abort()});var l=p(f,r.target);function p(r,o){return function(i){if(e.socket.destroyed&&"ECONNRESET"===i.code)return n.emit("econnreset",i,e,t,o),r.abort();s?s(i,e,t,o):n.emit("error",i,e,t,o)}}e.on("error",l),f.on("error",l),(r.buffer||e).pipe(f),f.on("response",function(o){if(n&&n.emit("proxyRes",o,e,t),!t.headersSent&&!r.selfHandleResponse)for(var s=0;s<z.length&&!z[s](e,t,o,r);s++);t.finished?n&&n.emit("end",e,t,o):(o.on("end",function(){n&&n.emit("end",e,t,o)}),r.selfHandleResponse||o.pipe(t))})}},J={checkMethodAndHeader:function(e,t){return"GET"===e.method&&e.headers.upgrade?"websocket"!==e.headers.upgrade.toLowerCase()?(t.destroy(),!0):void 0:(t.destroy(),!0)},XHeaders:function(e,t,r){if(r.xfwd){var o={for:e.connection.remoteAddress||e.socket.remoteAddress,port:m.getPort(e),proto:m.hasEncryptedConnection(e)?"wss":"ws"};["for","port","proto"].forEach(function(t){e.headers["x-forwarded-"+t]=(e.headers["x-forwarded-"+t]||"")+(e.headers["x-forwarded-"+t]?",":"")+o[t]})}},stream:function(e,t,r,o,n,s){var i=function(e,t){return Object.keys(t).reduce(function(e,r){var o=t[r];if(!Array.isArray(o))return e.push(r+": "+o),e;for(var n=0;n<o.length;n++)e.push(r+": "+o[n]);return e},[e]).join("\r\n")+"\r\n\r\n"};m.setupSocket(t),o&&o.length&&t.unshift(o);var a=(m.isSSL.test(r.target.protocol)?h.default:u.default).request(m.setupOutgoing(r.ssl||{},r,e));return n&&n.emit("proxyReqWs",a,e,t,r,o),a.on("error",c),a.on("response",function(e){e.upgrade||(t.write(i("HTTP/"+e.httpVersion+" "+e.statusCode+" "+e.statusMessage,e.headers)),e.pipe(t))}),a.on("upgrade",function(e,r,o){r.on("error",c),r.on("end",function(){n.emit("close",e,r,o)}),t.on("error",function(){r.end()}),m.setupSocket(r),o&&o.length&&r.unshift(o),t.write(i("HTTP/1.1 101 Switching Protocols",e.headers)),r.pipe(t).pipe(r),n.emit("open",r),n.emit("proxySocket",r)}),a.end();function c(r){s?s(r,e,t):n.emit("error",r,e,t),t.end()}}},V=d(function(e){var t=e.exports,r=a.default._extend,o=c.default.parse;function n(e){return function(t){return function(n,s){var i,a,c="ws"===e?this.wsPasses:this.webPasses,u=[].slice.call(arguments),h=u.length-1;"function"==typeof u[h]&&(a=u[h],h--);var f=t;if(u[h]instanceof Buffer||u[h]===s||(f=r({},t),r(f,u[h]),h--),u[h]instanceof Buffer&&(i=u[h]),["target","forward"].forEach(function(e){"string"==typeof f[e]&&(f[e]=o(f[e]))}),!f.target&&!f.forward)return this.emit("error",new Error("Must provide a proper URL as target"));for(var l=0;l<c.length&&!c[l](n,s,f,i,this,a);l++);}}}function s(e){g.call(this),(e=e||{}).prependPath=!1!==e.prependPath,this.web=this.proxyRequest=n("web")(e),this.ws=this.proxyWebsocketRequest=n("ws")(e),this.options=e,this.webPasses=Object.keys(G).map(function(e){return G[e]}),this.wsPasses=Object.keys(J).map(function(e){return J[e]}),this.on("error",this.onError,this)}t.Server=s,t.createRightProxy=n,a.default.inherits(s,g),s.prototype.onError=function(e){if(1===this.listeners("error").length)throw e},s.prototype.listen=function(e,t){var r=this,o=function(e,t){r.web(e,t)};return this._server=this.options.ssl?h.default.createServer(this.options.ssl,o):u.default.createServer(o),this.options.ws&&this._server.on("upgrade",function(e,t,o){r.ws(e,t,o)}),this._server.listen(e,t),this},s.prototype.close=function(e){var t=this;this._server&&this._server.close(function(){t._server=null,e&&e.apply(null,arguments)})},s.prototype.before=function(e,t,r){if("ws"!==e&&"web"!==e)throw new Error("type must be `web` or `ws`");var o="ws"===e?this.wsPasses:this.webPasses,n=!1;if(o.forEach(function(e,r){e.name===t&&(n=r)}),!1===n)throw new Error("No such pass");o.splice(n,0,r)},s.prototype.after=function(e,t,r){if("ws"!==e&&"web"!==e)throw new Error("type must be `web` or `ws`");var o="ws"===e?this.wsPasses:this.webPasses,n=!1;if(o.forEach(function(e,r){e.name===t&&(n=r)}),!1===n)throw new Error("No such pass");o.splice(n++,0,r)}}),X=V.Server;function K(e){return new X(e)}X.createProxyServer=K,X.createServer=K,X.createProxy=K;var Y=X,Z=require("http"),Q=require("../package.json").version,ee=require(process.cwd()+"/.localhostify.js"),te=process.argv[2];if(!te||!ee[te])throw new Error("Enviroment "+te+" not found!");var re=ee[te];if(!re.target||!re.target.host)throw new Error("No target!");re.allowHeaders=re.allowHeaders||"content-type",re.target=p({changeOrigin:!0,autoRewrite:!0,protocolRewrite:"http"},re.target),re.local=p({changeOrigin:!0,autoRewrite:!0,host:"http://localhost:3000"},re.local);var oe=Y.createProxyServer({changeOrigin:re.target.changeOrigin,autoRewrite:re.target.autoRewrite,protocolRewrite:re.target.protocolRewrite,target:re.target.host}),ne=Y.createProxyServer({changeOrigin:re.local.changeOrigin,autoRewrite:re.local.autoRewrite,target:re.local.host});oe.on("proxyReq",function(e,t){re.target.cookie&&e.setHeader("Cookie",re.target.cookie),e.setHeader("origin",re.target.host);var r=t.headers.referer,o=t.headers.origin;r&&o&&e.setHeader("referer",r.replace(o,re.target.host))}),oe.on("error",function(e){console.log(e)}),ne.on("error",function(e){console.log(e)});var se=Z.createServer(function(e,t){if("OPTIONS"!==e.method)new RegExp(re.target.matchUrl).test(e.url)?(console.log(e.method,re.target.host,e.url),oe.web(e,t)):(console.log(e.method,re.local.host,e.url),ne.web(e,t));else{t.setHeader("Access-Control-Allow-Headers",re.allowHeaders),t.setHeader("Access-Control-Allow-Methods","GET, PUT, POST, DELETE, HEAD");var r=e.headers.origin;r&&(t.setHeader("Access-Control-Allow-Origin",r),t.setHeader("Access-Control-Allow-Credentials","true")),t.end()}});se.on("upgrade",function(e,t,r){new RegExp(re.target.matchUrl).test(e.url)?(console.log("WS",re.target.host,e.url),oe.ws(e,t,r)):(console.log("WS",re.local.host,e.url),ne.ws(e,t,r))});var ie=Number(re.port||3001);console.log("\nlocalhostify "+Q),console.log("http://localhost:"+ie+" -> "+re.target.host),se.listen(ie); | ||
var e=require("util"),t=require("url"),r=require("http"),o=require("https"),n=require("stream"),s=require("assert");function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=/*#__PURE__*/i(e),c=/*#__PURE__*/i(t),u=/*#__PURE__*/i(r),h=/*#__PURE__*/i(o),l=/*#__PURE__*/i(n),f=/*#__PURE__*/i(s);function p(){return p=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o])}return e},p.apply(this,arguments)}function d(e){var t={exports:{}};return e(t,t.exports),t.exports}var g=d(function(e){var t=Object.prototype.hasOwnProperty,r="~";function o(){}function n(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function s(e,t,o,s,i){if("function"!=typeof o)throw new TypeError("The listener must be a function");var a=new n(o,s||e,i),c=r?r+t:t;return e._events[c]?e._events[c].fn?e._events[c]=[e._events[c],a]:e._events[c].push(a):(e._events[c]=a,e._eventsCount++),e}function i(e,t){0==--e._eventsCount?e._events=new o:delete e._events[t]}function a(){this._events=new o,this._eventsCount=0}Object.create&&(o.prototype=Object.create(null),(new o).__proto__||(r=!1)),a.prototype.eventNames=function(){var e,o,n=[];if(0===this._eventsCount)return n;for(o in e=this._events)t.call(e,o)&&n.push(r?o.slice(1):o);return Object.getOwnPropertySymbols?n.concat(Object.getOwnPropertySymbols(e)):n},a.prototype.listeners=function(e){var t=this._events[r?r+e:e];if(!t)return[];if(t.fn)return[t.fn];for(var o=0,n=t.length,s=new Array(n);o<n;o++)s[o]=t[o].fn;return s},a.prototype.listenerCount=function(e){var t=this._events[r?r+e:e];return t?t.fn?1:t.length:0},a.prototype.emit=function(e,t,o,n,s,i){var a=r?r+e:e;if(!this._events[a])return!1;var c,u,h=this._events[a],l=arguments.length;if(h.fn){switch(h.once&&this.removeListener(e,h.fn,void 0,!0),l){case 1:return h.fn.call(h.context),!0;case 2:return h.fn.call(h.context,t),!0;case 3:return h.fn.call(h.context,t,o),!0;case 4:return h.fn.call(h.context,t,o,n),!0;case 5:return h.fn.call(h.context,t,o,n,s),!0;case 6:return h.fn.call(h.context,t,o,n,s,i),!0}for(u=1,c=new Array(l-1);u<l;u++)c[u-1]=arguments[u];h.fn.apply(h.context,c)}else{var f,p=h.length;for(u=0;u<p;u++)switch(h[u].once&&this.removeListener(e,h[u].fn,void 0,!0),l){case 1:h[u].fn.call(h[u].context);break;case 2:h[u].fn.call(h[u].context,t);break;case 3:h[u].fn.call(h[u].context,t,o);break;case 4:h[u].fn.call(h[u].context,t,o,n);break;default:if(!c)for(f=1,c=new Array(l-1);f<l;f++)c[f-1]=arguments[f];h[u].fn.apply(h[u].context,c)}}return!0},a.prototype.on=function(e,t,r){return s(this,e,t,r,!1)},a.prototype.once=function(e,t,r){return s(this,e,t,r,!0)},a.prototype.removeListener=function(e,t,o,n){var s=r?r+e:e;if(!this._events[s])return this;if(!t)return i(this,s),this;var a=this._events[s];if(a.fn)a.fn!==t||n&&!a.once||o&&a.context!==o||i(this,s);else{for(var c=0,u=[],h=a.length;c<h;c++)(a[c].fn!==t||n&&!a[c].once||o&&a[c].context!==o)&&u.push(a[c]);u.length?this._events[s]=1===u.length?u[0]:u:i(this,s)}return this},a.prototype.removeAllListeners=function(e){var t;return e?this._events[t=r?r+e:e]&&i(this,t):(this._events=new o,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=r,a.EventEmitter=a,e.exports=a}),m=d(function(e,t){var r=t,o=a.default._extend,n=/(^|,)\s*upgrade\s*($|,)/i,s=/^https|wss/;r.isSSL=s,r.setupOutgoing=function(e,t,i,a){e.port=t[a||"target"].port||(s.test(t[a||"target"].protocol)?443:80),["host","hostname","socketPath","pfx","key","passphrase","cert","ca","ciphers","secureProtocol"].forEach(function(r){e[r]=t[a||"target"][r]}),e.method=t.method||i.method,e.headers=o({},i.headers),t.headers&&o(e.headers,t.headers),t.auth&&(e.auth=t.auth),t.ca&&(e.ca=t.ca),s.test(t[a||"target"].protocol)&&(e.rejectUnauthorized=void 0===t.secure||t.secure),e.agent=t.agent||!1,e.localAddress=t.localAddress,e.agent||(e.headers=e.headers||{},"string"==typeof e.headers.connection&&n.test(e.headers.connection)||(e.headers.connection="close"));var u=t[a||"target"],h=u&&!1!==t.prependPath&&u.path||"",l=t.toProxy?i.url:c.default.parse(i.url).path||"";return e.path=r.urlJoin(h,l=t.ignorePath?"":l),t.changeOrigin&&(e.headers.host=function(e,t){if(t=t.split(":")[0],!(e=+e))return!1;switch(t){case"http":case"ws":return 80!==e;case"https":case"wss":return 443!==e;case"ftp":return 21!==e;case"gopher":return 70!==e;case"file":return!1}return 0!==e}(e.port,t[a||"target"].protocol)&&!~e.host.indexOf(":")?e.host+":"+e.port:e.host),e},r.setupSocket=function(e){return e.setTimeout(0),e.setNoDelay(!0),e.setKeepAlive(!0,0),e},r.getPort=function(e){var t=e.headers.host?e.headers.host.match(/:(\d+)/):"";return t?t[1]:r.hasEncryptedConnection(e)?"443":"80"},r.hasEncryptedConnection=function(e){return Boolean(e.connection.encrypted||e.connection.pair)},r.urlJoin=function(){var e,t=Array.prototype.slice.call(arguments),r=t.length-1,o=t[r],n=o.split("?");return t[r]=n.shift(),(e=[t.filter(Boolean).join("/").replace(/\/+/g,"/").replace("http:/","http://").replace("https:/","https://")]).push.apply(e,n),e.join("?")},r.rewriteCookieProperty=function e(t,r,o){return Array.isArray(t)?t.map(function(t){return e(t,r,o)}):t.replace(new RegExp("(;\\s*"+o+"=)([^;]+)","i"),function(e,t,o){var n;if(o in r)n=r[o];else{if(!("*"in r))return e;n=r["*"]}return n?t+n:""})}}),v=/^201|30(1|2|7|8)$/,w={removeChunked:function(e,t,r){"1.0"===e.httpVersion&&delete r.headers["transfer-encoding"]},setConnection:function(e,t,r){"1.0"===e.httpVersion?r.headers.connection=e.headers.connection||"close":"2.0"===e.httpVersion||r.headers.connection||(r.headers.connection=e.headers.connection||"keep-alive")},setRedirectHostRewrite:function(e,t,r,o){if((o.hostRewrite||o.autoRewrite||o.protocolRewrite)&&r.headers.location&&v.test(r.statusCode)){var n=c.default.parse(o.target),s=c.default.parse(r.headers.location);if(n.host!=s.host)return;o.hostRewrite?s.host=o.hostRewrite:o.autoRewrite&&(s.host=e.headers.host),o.protocolRewrite&&(s.protocol=o.protocolRewrite),r.headers.location=s.format()}},writeHeaders:function(e,t,r,o){var n,s=o.cookieDomainRewrite,i=o.cookiePathRewrite,a=o.preserveHeaderKeyCase;if("string"==typeof s&&(s={"*":s}),"string"==typeof i&&(i={"*":i}),a&&null!=r.rawHeaders){n={};for(var c=0;c<r.rawHeaders.length;c+=2){var u=r.rawHeaders[c];n[u.toLowerCase()]=u}}Object.keys(r.headers).forEach(function(e){var o=r.headers[e];a&&n&&(e=n[e]||e),function(e,r){null!=r&&(s&&"set-cookie"===e.toLowerCase()&&(r=m.rewriteCookieProperty(r,s,"domain")),i&&"set-cookie"===e.toLowerCase()&&(r=m.rewriteCookieProperty(r,i,"path")),t.setHeader(String(e).trim(),r))}(e,o)})},writeStatusCode:function(e,t,r){r.statusMessage?(t.statusCode=r.statusCode,t.statusMessage=r.statusMessage):t.statusCode=r.statusCode}},y=1e3,C=60*y,_=60*C,b=24*_,R=function(e,t){t=t||{};var r=typeof e;if("string"===r&&e.length>0)return function(e){if(!((e=String(e)).length>100)){var t=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(t){var r=parseFloat(t[1]);switch((t[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return 315576e5*r;case"weeks":case"week":case"w":return 6048e5*r;case"days":case"day":case"d":return r*b;case"hours":case"hour":case"hrs":case"hr":case"h":return r*_;case"minutes":case"minute":case"mins":case"min":case"m":return r*C;case"seconds":case"second":case"secs":case"sec":case"s":return r*y;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return r;default:return}}}}(e);if("number"===r&&isFinite(e))return t.long?function(e){var t=Math.abs(e);return t>=b?x(e,t,b,"day"):t>=_?x(e,t,_,"hour"):t>=C?x(e,t,C,"minute"):t>=y?x(e,t,y,"second"):e+" ms"}(e):function(e){var t=Math.abs(e);return t>=b?Math.round(e/b)+"d":t>=_?Math.round(e/_)+"h":t>=C?Math.round(e/C)+"m":t>=y?Math.round(e/y)+"s":e+"ms"}(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))};function x(e,t,r,o){var n=t>=1.5*r;return Math.round(e/r)+" "+o+(n?"s":"")}var E,F=d(function(e,t){t.formatArgs=function(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const r="color: "+this.color;t.splice(1,0,r,"color: inherit");let o=0,n=0;t[0].replace(/%[a-zA-Z%]/g,e=>{"%%"!==e&&(o++,"%c"===e&&(n=o))}),t.splice(n,0,r)},t.save=function(e){try{e?t.storage.setItem("debug",e):t.storage.removeItem("debug")}catch(e){}},t.load=function(){let e;try{e=t.storage.getItem("debug")}catch(e){}return!e&&"undefined"!=typeof process&&"env"in process&&(e=process.env.DEBUG),e},t.useColors=function(){return!("undefined"==typeof window||!window.process||"renderer"!==window.process.type&&!window.process.__nwjs)||("undefined"==typeof navigator||!navigator.userAgent||!navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))&&("undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/))},t.storage=function(){try{return localStorage}catch(e){}}(),t.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],t.log=console.debug||console.log||(()=>{}),e.exports=function(e){function t(e){let o,n,s,i=null;function a(...e){if(!a.enabled)return;const r=a,n=Number(new Date);r.diff=n-(o||n),r.prev=o,r.curr=n,o=n,e[0]=t.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let s=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,(o,n)=>{if("%%"===o)return"%";s++;const i=t.formatters[n];return"function"==typeof i&&(o=i.call(r,e[s]),e.splice(s,1),s--),o}),t.formatArgs.call(r,e),(r.log||t.log).apply(r,e)}return a.namespace=e,a.useColors=t.useColors(),a.color=t.selectColor(e),a.extend=r,a.destroy=t.destroy,Object.defineProperty(a,"enabled",{enumerable:!0,configurable:!1,get:()=>null!==i?i:(n!==t.namespaces&&(n=t.namespaces,s=t.enabled(e)),s),set:e=>{i=e}}),"function"==typeof t.init&&t.init(a),a}function r(e,r){const o=t(this.namespace+(void 0===r?":":r)+e);return o.log=this.log,o}function o(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return t.debug=t,t.default=t,t.coerce=function(e){return e instanceof Error?e.stack||e.message:e},t.disable=function(){const e=[...t.names.map(o),...t.skips.map(o).map(e=>"-"+e)].join(",");return t.enable(""),e},t.enable=function(e){let r;t.save(e),t.namespaces=e,t.names=[],t.skips=[];const o=("string"==typeof e?e:"").split(/[\s,]+/),n=o.length;for(r=0;r<n;r++)o[r]&&("-"===(e=o[r].replace(/\*/g,".*?"))[0]?t.skips.push(new RegExp("^"+e.slice(1)+"$")):t.names.push(new RegExp("^"+e+"$")))},t.enabled=function(e){if("*"===e[e.length-1])return!0;let r,o;for(r=0,o=t.skips.length;r<o;r++)if(t.skips[r].test(e))return!1;for(r=0,o=t.names.length;r<o;r++)if(t.names[r].test(e))return!0;return!1},t.humanize=R,t.destroy=function(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")},Object.keys(e).forEach(r=>{t[r]=e[r]}),t.names=[],t.skips=[],t.formatters={},t.selectColor=function(e){let r=0;for(let t=0;t<e.length;t++)r=(r<<5)-r+e.charCodeAt(t),r|=0;return t.colors[Math.abs(r)%t.colors.length]},t.enable(t.load()),t}(t);const{formatters:r}=e.exports;r.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}}),k=function(){if(!E){try{E=F("follow-redirects")}catch(e){}"function"!=typeof E&&(E=function(){})}E.apply(null,arguments)},O=c.default.URL,q=l.default.Writable,A=["abort","aborted","connect","error","socket","timeout"],P=Object.create(null);A.forEach(function(e){P[e]=function(t,r,o){this._redirectable.emit(e,t,r,o)}});var S=D("ERR_FR_REDIRECTION_FAILURE","Redirected request failed"),L=D("ERR_FR_TOO_MANY_REDIRECTS","Maximum number of redirects exceeded"),T=D("ERR_FR_MAX_BODY_LENGTH_EXCEEDED","Request body larger than maxBodyLength limit"),j=D("ERR_STREAM_WRITE_AFTER_END","write after end");function H(e,t){q.call(this),this._sanitizeOptions(e),this._options=e,this._ended=!1,this._ending=!1,this._redirectCount=0,this._redirects=[],this._requestBodyLength=0,this._requestBodyBuffers=[],t&&this.on("response",t);var r=this;this._onNativeResponse=function(e){r._processResponse(e)},this._performRequest()}function B(e){var t={maxRedirects:21,maxBodyLength:10485760},r={};return Object.keys(e).forEach(function(o){var n=o+":",s=r[n]=e[o],i=t[o]=Object.create(s);Object.defineProperties(i,{request:{value:function(e,o,s){if("string"==typeof e){var i=e;try{e=M(new O(i))}catch(t){e=c.default.parse(i)}}else O&&e instanceof O?e=M(e):(s=o,o=e,e={protocol:n});return"function"==typeof o&&(s=o,o=null),(o=Object.assign({maxRedirects:t.maxRedirects,maxBodyLength:t.maxBodyLength},e,o)).nativeProtocols=r,f.default.equal(o.protocol,n,"protocol mismatch"),k("options",o),new H(o,s)},configurable:!0,enumerable:!0,writable:!0},get:{value:function(e,t,r){var o=i.request(e,t,r);return o.end(),o},configurable:!0,enumerable:!0,writable:!0}})}),t}function N(){}function M(e){var t={protocol:e.protocol,hostname:e.hostname.startsWith("[")?e.hostname.slice(1,-1):e.hostname,hash:e.hash,search:e.search,pathname:e.pathname,path:e.pathname+e.search,href:e.href};return""!==e.port&&(t.port=Number(e.port)),t}function U(e,t){var r;for(var o in t)e.test(o)&&(r=t[o],delete t[o]);return null==r?void 0:String(r).trim()}function D(e,t){function r(e){Error.captureStackTrace(this,this.constructor),e?(this.message=t+": "+e.message,this.cause=e):this.message=t}return(r.prototype=new Error).constructor=r,r.prototype.name="Error ["+e+"]",r.prototype.code=e,r}function I(e){for(var t=0;t<A.length;t++)e.removeListener(A[t],P[A[t]]);e.on("error",N),e.abort()}(H.prototype=Object.create(q.prototype)).abort=function(){I(this._currentRequest),this.emit("abort")},H.prototype.write=function(e,t,r){if(this._ending)throw new j;if(!("string"==typeof e||"object"==typeof e&&"length"in e))throw new TypeError("data should be a string, Buffer or Uint8Array");"function"==typeof t&&(r=t,t=null),0!==e.length?this._requestBodyLength+e.length<=this._options.maxBodyLength?(this._requestBodyLength+=e.length,this._requestBodyBuffers.push({data:e,encoding:t}),this._currentRequest.write(e,t,r)):(this.emit("error",new T),this.abort()):r&&r()},H.prototype.end=function(e,t,r){if("function"==typeof e?(r=e,e=t=null):"function"==typeof t&&(r=t,t=null),e){var o=this,n=this._currentRequest;this.write(e,t,function(){o._ended=!0,n.end(null,null,r)}),this._ending=!0}else this._ended=this._ending=!0,this._currentRequest.end(null,null,r)},H.prototype.setHeader=function(e,t){this._options.headers[e]=t,this._currentRequest.setHeader(e,t)},H.prototype.removeHeader=function(e){delete this._options.headers[e],this._currentRequest.removeHeader(e)},H.prototype.setTimeout=function(e,t){var r=this;function o(t){t.setTimeout(e),t.removeListener("timeout",t.destroy),t.addListener("timeout",t.destroy)}function n(t){r._timeout&&clearTimeout(r._timeout),r._timeout=setTimeout(function(){r.emit("timeout"),s()},e),o(t)}function s(){r._timeout&&(clearTimeout(r._timeout),r._timeout=null),r.removeListener("abort",s),r.removeListener("error",s),r.removeListener("response",s),t&&r.removeListener("timeout",t),r.socket||r._currentRequest.removeListener("socket",n)}return t&&this.on("timeout",t),this.socket?n(this.socket):this._currentRequest.once("socket",n),this.on("socket",o),this.on("abort",s),this.on("error",s),this.on("response",s),this},["flushHeaders","getHeader","setNoDelay","setSocketKeepAlive"].forEach(function(e){H.prototype[e]=function(t,r){return this._currentRequest[e](t,r)}}),["aborted","connection","socket"].forEach(function(e){Object.defineProperty(H.prototype,e,{get:function(){return this._currentRequest[e]}})}),H.prototype._sanitizeOptions=function(e){if(e.headers||(e.headers={}),e.host&&(e.hostname||(e.hostname=e.host),delete e.host),!e.pathname&&e.path){var t=e.path.indexOf("?");t<0?e.pathname=e.path:(e.pathname=e.path.substring(0,t),e.search=e.path.substring(t))}},H.prototype._performRequest=function(){var e=this._options.protocol,t=this._options.nativeProtocols[e];if(t){if(this._options.agents){var r=e.slice(0,-1);this._options.agent=this._options.agents[r]}var o=this._currentRequest=t.request(this._options,this._onNativeResponse);this._currentUrl=c.default.format(this._options),o._redirectable=this;for(var n=0;n<A.length;n++)o.on(A[n],P[A[n]]);if(this._isRedirect){var s=0,i=this,a=this._requestBodyBuffers;!function e(t){if(o===i._currentRequest)if(t)i.emit("error",t);else if(s<a.length){var r=a[s++];o.finished||o.write(r.data,r.encoding,e)}else i._ended&&o.end()}()}}else this.emit("error",new TypeError("Unsupported protocol "+e))},H.prototype._processResponse=function(e){var t=e.statusCode;this._options.trackRedirects&&this._redirects.push({url:this._currentUrl,headers:e.headers,statusCode:t});var r=e.headers.location;if(!r||!1===this._options.followRedirects||t<300||t>=400)return e.responseUrl=this._currentUrl,e.redirects=this._redirects,this.emit("response",e),void(this._requestBodyBuffers=[]);if(I(this._currentRequest),e.destroy(),++this._redirectCount>this._options.maxRedirects)this.emit("error",new L);else{var o,n=this._options.beforeRedirect;n&&(o=Object.assign({Host:e.req.getHeader("host")},this._options.headers));var s=this._options.method;((301===t||302===t)&&"POST"===this._options.method||303===t&&!/^(?:GET|HEAD)$/.test(this._options.method))&&(this._options.method="GET",this._requestBodyBuffers=[],U(/^content-/i,this._options.headers));var i,a=U(/^host$/i,this._options.headers),u=c.default.parse(this._currentUrl),h=a||u.host,l=/^\w+:/.test(r)?this._currentUrl:c.default.format(Object.assign(u,{host:h}));try{i=c.default.resolve(l,r)}catch(e){return void this.emit("error",new S(e))}k("redirecting to",i),this._isRedirect=!0;var f=c.default.parse(i);if(Object.assign(this._options,f),(f.protocol!==u.protocol&&"https:"!==f.protocol||f.host!==h&&!function(e,t){const r=e.length-t.length-1;return r>0&&"."===e[r]&&e.endsWith(t)}(f.host,h))&&U(/^(?:authorization|cookie)$/i,this._options.headers),"function"==typeof n){var p={headers:e.headers,statusCode:t},d={url:l,method:s,headers:o};try{n(this._options,p,d)}catch(e){return void this.emit("error",e)}this._sanitizeOptions(this._options)}try{this._performRequest()}catch(e){this.emit("error",new S(e))}}};var $=B({http:u.default,https:h.default});$.wrap=B;var z=w;z=Object.keys(z).map(function(e){return z[e]});var W={http:u.default,https:h.default},G={deleteLength:function(e,t,r){"DELETE"!==e.method&&"OPTIONS"!==e.method||e.headers["content-length"]||(e.headers["content-length"]="0",delete e.headers["transfer-encoding"])},timeout:function(e,t,r){r.timeout&&e.socket.setTimeout(r.timeout)},XHeaders:function(e,t,r){if(r.xfwd){var o=e.isSpdy||m.hasEncryptedConnection(e),n={for:e.connection.remoteAddress||e.socket.remoteAddress,port:m.getPort(e),proto:o?"https":"http"};["for","port","proto"].forEach(function(t){e.headers["x-forwarded-"+t]=(e.headers["x-forwarded-"+t]||"")+(e.headers["x-forwarded-"+t]?",":"")+n[t]}),e.headers["x-forwarded-host"]=e.headers["x-forwarded-host"]||e.headers.host||""}},stream:function(e,t,r,o,n,s){n.emit("start",e,t,r.target||r.forward);var i=r.followRedirects?$:W,a=i.http,c=i.https;if(r.forward){var u=("https:"===r.forward.protocol?c:a).request(m.setupOutgoing(r.ssl||{},r,e,"forward")),h=p(u,r.forward);if(e.on("error",h),u.on("error",h),(r.buffer||e).pipe(u),!r.target)return t.end()}var l=("https:"===r.target.protocol?c:a).request(m.setupOutgoing(r.ssl||{},r,e));l.on("socket",function(o){n&&!l.getHeader("expect")&&n.emit("proxyReq",l,e,t,r)}),r.proxyTimeout&&l.setTimeout(r.proxyTimeout,function(){l.abort()}),e.on("aborted",function(){l.abort()});var f=p(l,r.target);function p(r,o){return function(i){if(e.socket.destroyed&&"ECONNRESET"===i.code)return n.emit("econnreset",i,e,t,o),r.abort();s?s(i,e,t,o):n.emit("error",i,e,t,o)}}e.on("error",f),l.on("error",f),(r.buffer||e).pipe(l),l.on("response",function(o){if(n&&n.emit("proxyRes",o,e,t),!t.headersSent&&!r.selfHandleResponse)for(var s=0;s<z.length&&!z[s](e,t,o,r);s++);t.finished?n&&n.emit("end",e,t,o):(o.on("end",function(){n&&n.emit("end",e,t,o)}),r.selfHandleResponse||o.pipe(t))})}},J={checkMethodAndHeader:function(e,t){return"GET"===e.method&&e.headers.upgrade?"websocket"!==e.headers.upgrade.toLowerCase()?(t.destroy(),!0):void 0:(t.destroy(),!0)},XHeaders:function(e,t,r){if(r.xfwd){var o={for:e.connection.remoteAddress||e.socket.remoteAddress,port:m.getPort(e),proto:m.hasEncryptedConnection(e)?"wss":"ws"};["for","port","proto"].forEach(function(t){e.headers["x-forwarded-"+t]=(e.headers["x-forwarded-"+t]||"")+(e.headers["x-forwarded-"+t]?",":"")+o[t]})}},stream:function(e,t,r,o,n,s){var i=function(e,t){return Object.keys(t).reduce(function(e,r){var o=t[r];if(!Array.isArray(o))return e.push(r+": "+o),e;for(var n=0;n<o.length;n++)e.push(r+": "+o[n]);return e},[e]).join("\r\n")+"\r\n\r\n"};m.setupSocket(t),o&&o.length&&t.unshift(o);var a=(m.isSSL.test(r.target.protocol)?h.default:u.default).request(m.setupOutgoing(r.ssl||{},r,e));return n&&n.emit("proxyReqWs",a,e,t,r,o),a.on("error",c),a.on("response",function(e){e.upgrade||(t.write(i("HTTP/"+e.httpVersion+" "+e.statusCode+" "+e.statusMessage,e.headers)),e.pipe(t))}),a.on("upgrade",function(e,r,o){r.on("error",c),r.on("end",function(){n.emit("close",e,r,o)}),t.on("error",function(){r.end()}),m.setupSocket(r),o&&o.length&&r.unshift(o),t.write(i("HTTP/1.1 101 Switching Protocols",e.headers)),r.pipe(t).pipe(r),n.emit("open",r),n.emit("proxySocket",r)}),a.end();function c(r){s?s(r,e,t):n.emit("error",r,e,t),t.end()}}},V=d(function(e){var t=e.exports,r=a.default._extend,o=c.default.parse;function n(e){return function(t){return function(n,s){var i,a,c="ws"===e?this.wsPasses:this.webPasses,u=[].slice.call(arguments),h=u.length-1;"function"==typeof u[h]&&(a=u[h],h--);var l=t;if(u[h]instanceof Buffer||u[h]===s||(l=r({},t),r(l,u[h]),h--),u[h]instanceof Buffer&&(i=u[h]),["target","forward"].forEach(function(e){"string"==typeof l[e]&&(l[e]=o(l[e]))}),!l.target&&!l.forward)return this.emit("error",new Error("Must provide a proper URL as target"));for(var f=0;f<c.length&&!c[f](n,s,l,i,this,a);f++);}}}function s(e){g.call(this),(e=e||{}).prependPath=!1!==e.prependPath,this.web=this.proxyRequest=n("web")(e),this.ws=this.proxyWebsocketRequest=n("ws")(e),this.options=e,this.webPasses=Object.keys(G).map(function(e){return G[e]}),this.wsPasses=Object.keys(J).map(function(e){return J[e]}),this.on("error",this.onError,this)}t.Server=s,t.createRightProxy=n,a.default.inherits(s,g),s.prototype.onError=function(e){if(1===this.listeners("error").length)throw e},s.prototype.listen=function(e,t){var r=this,o=function(e,t){r.web(e,t)};return this._server=this.options.ssl?h.default.createServer(this.options.ssl,o):u.default.createServer(o),this.options.ws&&this._server.on("upgrade",function(e,t,o){r.ws(e,t,o)}),this._server.listen(e,t),this},s.prototype.close=function(e){var t=this;this._server&&this._server.close(function(){t._server=null,e&&e.apply(null,arguments)})},s.prototype.before=function(e,t,r){if("ws"!==e&&"web"!==e)throw new Error("type must be `web` or `ws`");var o="ws"===e?this.wsPasses:this.webPasses,n=!1;if(o.forEach(function(e,r){e.name===t&&(n=r)}),!1===n)throw new Error("No such pass");o.splice(n,0,r)},s.prototype.after=function(e,t,r){if("ws"!==e&&"web"!==e)throw new Error("type must be `web` or `ws`");var o="ws"===e?this.wsPasses:this.webPasses,n=!1;if(o.forEach(function(e,r){e.name===t&&(n=r)}),!1===n)throw new Error("No such pass");o.splice(n++,0,r)}}),X=V.Server;function K(e){return new X(e)}X.createProxyServer=K,X.createServer=K,X.createProxy=K;var Y=X,Z=require("http"),Q=require("../package.json").version,ee=require(process.cwd()+"/.localhostify.js"),te=process.argv[2];if(!te||!ee[te])throw new Error("Enviroment "+te+" not found!");var re=ee[te];if(!re.target||!re.target.host)throw new Error("No target!");re.allowHeaders=re.allowHeaders||"content-type",re.target=p({changeOrigin:!0,autoRewrite:!0,protocolRewrite:"http"},re.target),re.local=p({changeOrigin:!0,autoRewrite:!0,host:"http://localhost:3000"},re.local);var oe=Y.createProxyServer({changeOrigin:re.target.changeOrigin,autoRewrite:re.target.autoRewrite,protocolRewrite:re.target.protocolRewrite,target:re.target.host}),ne=Y.createProxyServer({changeOrigin:re.local.changeOrigin,autoRewrite:re.local.autoRewrite,target:re.local.host}),se=Array.isArray(re.externalRedirects)?re.externalRedirects:[];oe.on("proxyRes",function(e){if(e.headers.location){var t=e.headers.location;se.forEach(function(e){new RegExp(e.match).test(t)&&(t=t.replace(e.replace[0],e.replace[1]))}),e.headers.location=t}}),oe.on("proxyReq",function(e,t){re.target.cookie&&e.setHeader("Cookie",re.target.cookie),e.setHeader("origin",re.target.host);var r=t.headers.referer,o=t.headers.origin;r&&o&&e.setHeader("referer",r.replace(o,re.target.host))}),oe.on("error",function(e){console.log(e)}),ne.on("error",function(e){console.log(e)});var ie=Z.createServer(function(e,t){if("OPTIONS"!==e.method)new RegExp(re.target.matchUrl).test(e.url)?(console.log(e.method,re.target.host,e.url),oe.web(e,t)):(console.log(e.method,re.local.host,e.url),ne.web(e,t));else{t.setHeader("Access-Control-Allow-Headers",re.allowHeaders),t.setHeader("Access-Control-Allow-Methods","GET, PUT, POST, DELETE, HEAD");var r=e.headers.origin;r&&(t.setHeader("Access-Control-Allow-Origin",r),t.setHeader("Access-Control-Allow-Credentials","true")),t.end()}});ie.on("upgrade",function(e,t,r){new RegExp(re.target.matchUrl).test(e.url)?(console.log("WS",re.target.host,e.url),oe.ws(e,t,r)):(console.log("WS",re.local.host,e.url),ne.ws(e,t,r))});var ae=Number(re.port||3001);console.log("\nlocalhostify "+Q),console.log("http://localhost:"+ae+" -> "+re.target.host),ie.listen(ae); |
{ | ||
"name": "localhostify", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "Easy HTTP reverse proxy - localhost:3001 -> prod.domain.com", | ||
@@ -17,4 +17,4 @@ "source": "src/index.js", | ||
"http-proxy": "^1.18.1", | ||
"microbundle": "^0.14.0", | ||
"prettier": "2.4.1" | ||
"microbundle": "^0.15.0", | ||
"prettier": "^2.6.2" | ||
}, | ||
@@ -21,0 +21,0 @@ "scripts": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
47415
274