Skip to content

Commit

Permalink
processUrl function cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rgallettonf committed Feb 5, 2025
1 parent e1dd165 commit bfb4708
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,20 @@ const processControllerUrls = (urlString) => {
}
const urls = urlString.split(',').map(url => url.trim());
const validUrls = urls.map(url => {
// If the URL doesn't have a protocol, prepend 'https://'
// If the controller URL doesn't have a protocol, prepend 'https://'
if (!/^https?:\/\//i.test(url)) {
url = 'https://' + url;
}
try {
// Validate the URL using the URL constructor
const validatedUrl = new URL(url);
const ctrlUrl = validatedUrl.toString().replace(/\/$/, '');
const setting = { name: ctrlUrl, url: ctrlUrl, default: false };
return setting; // Return the fully qualified URL (including the protocol)
return setting;
} catch (error) {
// If URL is invalid, log an error and return null or handle as needed
console.error(`Invalid URL: ${url}`);
log(`Invalid URL: ${url}`);
return null;
}
}).filter(Boolean) || []; // Remove any null values (invalid URLs)
}).filter(Boolean) || [];
return validUrls;
};

Expand Down

0 comments on commit bfb4708

Please sign in to comment.