2018-06-25 17:42:50 +00:00
|
|
|
import { parse as urlParse } from 'url';
|
2017-06-21 21:20:42 +00:00
|
|
|
|
2017-06-21 20:56:19 +00:00
|
|
|
const WILDCARD_CHARACTER = '*';
|
2018-06-25 17:42:50 +00:00
|
|
|
const WILDCARD_SUBSTITUTION = Math.random()
|
|
|
|
.toString()
|
|
|
|
.split('.')[1];
|
2018-10-17 16:42:33 +00:00
|
|
|
const WILDCARD_SUBSTITUTION_PATTERN = new RegExp(`${WILDCARD_SUBSTITUTION}`, 'g');
|
2017-06-21 20:56:19 +00:00
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
export default function certificateUrlParse(url) {
|
2017-06-21 20:56:19 +00:00
|
|
|
if (url.indexOf(WILDCARD_CHARACTER) === -1) {
|
|
|
|
return urlParse(url);
|
|
|
|
} else {
|
|
|
|
const parsed = urlParse(url.replace(/\*/g, WILDCARD_SUBSTITUTION));
|
2017-06-21 21:20:42 +00:00
|
|
|
parsed.hostname = _reinstateWildcards(parsed.hostname);
|
|
|
|
parsed.host = _reinstateWildcards(parsed.host);
|
|
|
|
parsed.href = _reinstateWildcards(parsed.href);
|
2017-11-04 21:00:16 +00:00
|
|
|
parsed.port = _reinstateWildcards(parsed.port);
|
2017-06-21 20:56:19 +00:00
|
|
|
|
|
|
|
return parsed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
function _reinstateWildcards(string) {
|
2017-06-21 20:56:19 +00:00
|
|
|
if (string) {
|
|
|
|
return string.replace(WILDCARD_SUBSTITUTION_PATTERN, WILDCARD_CHARACTER);
|
|
|
|
} else {
|
|
|
|
return string;
|
|
|
|
}
|
2017-06-21 21:20:42 +00:00
|
|
|
}
|