如果你比較以下兩個電話,你會看到加入議定書字符串前造成很大的差異:
> url.parse('http://localhost:3000', '/whatever/')
{ protocol: 'http:',
slashes: true,
auth: null,
host: 'localhost:3000',
port: '3000',
hostname: 'localhost',
hash: null,
search: '',
query: {},
pathname: '/',
path: '/',
href: 'http://localhost:3000/' }
>
沒有
> url.parse('localhost:3000', '/whatever/')
{ protocol: 'localhost:',
slashes: null,
auth: null,
host: '3000',
port: null,
hostname: '3000',
hash: null,
search: '',
query: {},
pathname: null,
path: null,
href: 'localhost:3000' }
>
什麼你可能尋找添加協議,然後使用+
而不是,
:
> url.parse('http://localhost:3000' + '/whatever/')
{ protocol: 'http:',
slashes: true,
auth: null,
host: 'localhost:3000',
port: '3000',
hostname: 'localhost',
hash: null,
search: null,
query: null,
pathname: '/whatever/',
path: '/whatever/',
href: 'http://localhost:3000/whatever/' }
>
'url.parse'只需要一個字符串參數。 –