hapi-bouncer
Version:
hapi bouncer proxy
81 lines (64 loc) • 2.33 kB
JavaScript
;
exports.__esModule = true;
var _url = require('url');
var _url2 = _interopRequireDefault(_url);
var _path = require('path');
var _path2 = _interopRequireDefault(_path);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var LOCAL_PROTOCOLS = ['file', 'directory'];
var PROTOCOL_SEP = '://';
// {
// protocol?: string;
// slashes?: boolean;
// auth?: string;
// host?: string;
// port?: string;
// hostname?: string;
// hash?: string;
// search?: string;
// query?: any; // null | string | Object
// pathname?: string;
// path?: string;
// href: string;
// }
var ParsedUrl = function () {
function ParsedUrl(link) {
_classCallCheck(this, ParsedUrl);
var localProtocol = LOCAL_PROTOCOLS.filter(function (p) {
return link.indexOf(p + PROTOCOL_SEP) === 0;
})[0];
var p = void 0;
if (localProtocol) {
this.isLocalProtocol = true;
this.protocol = localProtocol;
this.port = 0;
this.path = '';
this.hostname = link.substring(localProtocol.length + PROTOCOL_SEP.length);
} else {
var _url$parse = _url2.default.parse(link),
protocol = _url$parse.protocol,
port = _url$parse.port,
hostname = _url$parse.hostname,
pth = _url$parse.path;
this.protocol = protocol ? protocol.substring(0, protocol.length - 1) : '';
if (port) {
this.port = Number(port);
}
this.path = pth || '';
this.hostname = hostname || '';
}
}
ParsedUrl.prototype.getHostUrl = function getHostUrl() {
var port = !this.port || this.port === 443 || this.port === 80 ? '' : String(this.port);
var pth = this.path;
var l = pth.length - 1;
if (pth[l] === '/') {
pth = pth.substring(0, l);
}
return this.protocol + '://' + this.hostname + port + pth;
};
return ParsedUrl;
}();
exports.default = ParsedUrl;
//# sourceMappingURL=ParsedUrl.js.map