1 |
|
2 | 'use strict';
|
3 |
|
4 | module.exports = function (address) {
|
5 | var url = require('url');
|
6 |
|
7 | var parseUrl = function (address) {
|
8 | var protocol = url.parse(address).protocol || null;
|
9 |
|
10 | if (protocol === 'http:' || protocol === 'https:') {
|
11 | return url.parse(address);
|
12 | }
|
13 |
|
14 | return url.parse('http://' + address);
|
15 | };
|
16 |
|
17 | var map = function (address) {
|
18 | var mappedRoute = {};
|
19 | var route = parseUrl(address);
|
20 |
|
21 | mappedRoute.protocol = route.protocol || null;
|
22 | mappedRoute.host = route.hostname || null;
|
23 | mappedRoute.port = route.port || null;
|
24 |
|
25 | return mappedRoute;
|
26 | };
|
27 |
|
28 | return map(address);
|
29 | };
|