Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why new URL() method removes one part of my url passed as a base url

I created a snippet to show the issue below

I have the following values to create my URL

const baseUrl = 'https://s3.xxx.xxx.com/xyz.xxx.xxx.twilio';
const accessCode = 'accesscode_he-ar_IL.mp3';

When I run new URL() the result is https://s3.xxx.xxx.com/accesscode_he-ar_IL.mp3

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Why the middle part is removed as xyz.xxx.xxx.twilio

I have no clue why the method removes part of my URL and this results in a fail for me as I need to get data from that path.

const baseUrl = 'https://s3.xxx.xxx.com/xyz.xxx.xxx.twilio';
const accessCode = 'accesscode_he-ar_IL.mp3';

const res = new URL(accessCode, baseUrl);

console.log(res);

>Solution :

You forgot to add an extra / at the end of your baseUrl : const baseUrl = 'https://s3.xxx.xxx.com/xyz.xxx.xxx.twilio/'

const baseUrl = 'https://s3.xxx.xxx.com/xyz.xxx.xxx.twilio/';
const accessCode = 'accesscode_he-ar_IL.mp3';

const res = new URL(accessCode, baseUrl);

console.log(res);

The URL() method replace the current page (which in your case was xyz.xxx.xxx.twilio) by the new page passed through the access code.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading