Created
September 14, 2017 11:17
-
-
Save lusan/5aca36f0b9eafe61e04ff173010bb783 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const removeBaseUrl = (url) => { | |
/* | |
* Replace base URL in given string, if it exists, and return the result. | |
* | |
* e.g. "http://localhost:8000/api/v1/blah/" becomes "/api/v1/blah/" | |
* "/api/v1/blah/" stays "/api/v1/blah/" | |
*/ | |
const baseUrlPattern = /^https?:\/\/[a-z\:0-9.]+/; | |
let result = ""; | |
let match = baseUrlPattern.exec(url); | |
if (match != null) { | |
result = match[0]; | |
} | |
if (result.length > 0) { | |
url = url.replace(result, ""); | |
} | |
return url; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment