Reputation: 588
Does Node.js have a URL module to resolve this?
getCorrectUrl('http://www.domain.com/folder/folder/', '../../img/some.jpg'); // http://www.domain.com/img/some.jpg
getCorrectUrl('http://www.domain.com/folder/folder/', './img/some.jpg'); // http://www.domain.com/img/some.jpg
getCorrectUrl('http://www.domain.com/folder/folder/', 'http://www.domain.com/img/some.jpg'); // http://www.domain.com/img/some.jpg
getCorrectUrl('http://www.domain.com/folder/folder/', '../img/some.jpg'); // http://www.domain.com/folder/img/some.jpg
getCorrectUrl('http://www.domain.com/folder/folder/', 'img/some.jpg'); // http://www.domain.com/folder/folder/img/some.jpg
Upvotes: 3
Views: 171
Reputation: 91609
Use the native URL module. What you'd be looking for is url.resolve()
.
url.resolve('http://www.domain.com/folder/folder/', '../img/some.jpg');
// http://www.domain.com/folder/img/some.jpg
Upvotes: 4