Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split url based on environment

I have the below urls based on environment separated by hyphen.

  1. www-dev.someurl.com for dev environment
  2. www-qa.someurl.com for qa environment
  3. www.someurl.com for production, no environment prefix

In one my code snippets i want to dynamically build the above url based on environment by reading from url (either using $location.host() or window.location.hostname)

can anyone suggest a regex or some code to find out if in the Url there is a envirnment variable (dev/qa)

if(contains dev/qa){
    //build url
    } else {
        //build production url
 }

Please suggest the best option using regex/code snippet

like image 966
user804401 Avatar asked Mar 08 '26 13:03

user804401


1 Answers

As per your earlier comment 'rather than passing qa/dev in regex is there any way where i can get value after hyphen' , how about this instead of regex :

 if((window.location.hostname).indexOf('-')>=0){
     var env= (window.location.hostname).split('-')[1];
     // possible output of env : dev.someurl.com,qa.someurl.com
    }
    else{
    //prod
    }
like image 165
Aditya Avatar answered Mar 11 '26 02:03

Aditya



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!