Ember Host Manager
Host management solution for ambitious Ember applications
Features
- Easily manage different host configurations
- Specify different API settings
- Declare feature flags for specific hosts / environments
- and much more!
- Access the current host config anywhere in your app
- Host override allows you to grab your host name from anywhere
- Fallback config if nothing matches
- Test configuration
- Simple mirage integration
Installation
ember install ember-host-manager
Helpful Links
Looking for help?
If it is a bug please open an issue on GitHub.
Usage
Hosts Configuration
When you install this addon, a config/hosts.js
file will be created which will hold all the different hosts and their
configurations.
It will look something like this:
module { return /* If present, the host configuration will be pulled based on the given string. ex) `APP_HOST=myapp.com ember s` */ //hostOverride: process.env.APP_HOST, /* If the host doesn't resolve to any of the defined configs here, this will be the config used */ 'default': {} /* This is the host config that will be used in the test environment */ 'test': {} ;};
Lets add some host configurations for our dev and prod environments.
module { return /* Fallback to prod */ 'default': apiHost: 'http://myapp.prod.api/' apiNamespace: 'v2' /* Use mirage in tests with `api` namespace */ 'test': apiHost: '' apiNamespace: 'api' /* Dev Hosts These must be added to /etc/hosts and mapped to localhost */ 'dev.myapp.com:4200': apiHost: 'http://myapp.dev.api/' apiNamespace: 'v2' 'stg.myapp.com:4200': apiHost: 'http://myapp.stg.api/' apiNamespace: 'v2' 'prod.myapp.com:4200': apiHost: 'http://myapp.prod.api/' apiNamespace: 'v2' /* Production Hosts */ 'myapp.com' apiHost: 'http://myapp.prod.api/' apiNamespace: 'v2' 'myapp.com:443' apiHost: 'https://myapp.prod.api/' apiNamespace: 'v2' ;};
Note: You will need to add the following to your /etc/hosts
config to get the
dev hosts to work. Once done, you can open your browser and navigate to any of the
3 specified hosts which will then use their appropriate config.
# MyApp Dev Environments localhost dev.myapp.comlocalhost stg.myapp.comlocalhost prod.myapp.com
Accessing the Host Config
There are two ways you can access the current host config:
1. Import
// Get the current host; // Get all available hosts
1. Service
// adapters/application.js RESTAdapter;
The Host Manager Service
The Host Manager service not only gives you access to the current host via the host
property, but allows you to get any host config via the getHost
method.
Controller;