19 lines
346 B
JavaScript
19 lines
346 B
JavaScript
function get_hostname(url) {
|
|
if (!url) return undefined;
|
|
if (url.indexOf("://") > -1) {
|
|
url = url.split("/")[2];
|
|
}
|
|
return url.match(/:/g) ? url.slice(0, url.indexOf(":")) : url;
|
|
}
|
|
|
|
function get_url(socket, path) {
|
|
if (!path) {
|
|
path = "";
|
|
}
|
|
return socket.request.headers.origin + path;
|
|
}
|
|
|
|
module.exports = {
|
|
get_url,
|
|
get_hostname,
|
|
};
|