In the runtime / app editor
One way to accomplish this is to write a function in your shared JS as follows:
function sharedEnv() {
if(journey && journey.server) {
return journey.server
} else return null;
}
This will return the url of the environment, e.g. https://run-testing.journeyapps.com
.
To make this useful, you can use the following function in your view to determine if you are in e.g. testing
or staging
.
if(sharedEnv().indexOf('testing') > -1) {
//do logic or show a button for testing only
}
In CloudCode
CloudCode also exposes the environment in a variable, but directly:
export async function run() {
//returns the evironment the function is running in; testing, staging, production
console.log(`${this.env}`)
}
The above function returns the following: