Skip to content

Instantly share code, notes, and snippets.

@jmosul
Last active October 1, 2017 18:04
Show Gist options
  • Save jmosul/41e8f3025cfb38139840b2c2ad0f6bc7 to your computer and use it in GitHub Desktop.
Save jmosul/41e8f3025cfb38139840b2c2ad0f6bc7 to your computer and use it in GitHub Desktop.
ES6 class for supporting Urls in my applications that talk to my api
const JadeConfig = {
environment: 'prod',
domain: 'jamesmosullivan',
topLevelDomain: 'uk'
};
class JadeService {
constructor( $window, JadeConfig = {} ){
this.JadeConfig = JadeConfig;
this._env = this.JadeConfig.environment || this._parseHref( $window.location.href );
}
get environment() {
return this._env;
}
get domain(){
return this.JadeConfig.domain || 'jamesmosullivan';
}
get topLevelDomain(){
return this.isDev() ? 'dev' : this.JadeConfig.topLevelDomain || 'uk';
}
get uri() {
return `${this.domain}.${this.topLevelDomain}`;
}
get apiBase() {
return `api.${this.uri}`;
}
isDev(){
return this.environment === 'dev';
}
/**
* Determines environment from given href
*
* @param href
* @returns {string}
* @private
*/
_parseHref( href ){
return href.indexOf( `${this.domain}.dev`) > 0 ? 'dev' : 'prod';
}
}
{
"name": "jade-service",
"version": "1.0.0",
"description": "Core ES6 class contacting services within Jade (Jmosul Application Development Enviroment",
"author": "James O'Sullivan"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment