Created
February 3, 2018 03:01
-
-
Save wichopy/f4eac30169f6c91497c12ee716b11ea4 to your computer and use it in GitHub Desktop.
Filter out text strings using regex of a URL.
This file contains hidden or 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
// assuming env var | |
// BASE_URL=www.mydomain.com | |
removebaseURL = (fullURL) => { // pass in (www.mydomain.com/kittens) | |
// Allow api calls to handle just the end point (/kittens) or the full URL (www.mydomain.com/kittens) | |
// by filtering out the base URL if the route contains it. | |
const reg = new RegExp(process.env.BASE_URL, 'gi'); | |
const match = fullURL.match(r eg) | |
let endpoint | |
if (match) { | |
endpoint = fullURL.split(reg)[1] | |
} else { | |
endpoint = fullURL | |
} | |
return endpoint // returns kittens | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment