Giter Site home page Giter Site logo

ember-host-manager's Introduction

Ember Host Manager

Build Status npm version Dependency Status devDependency Status

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.exports = function(/* environment */) {
  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.exports = function(/* environment */) {
  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.com
localhost stg.myapp.com
localhost prod.myapp.com

Accessing the Host Config

There are two ways you can access the current host config:

1. Import

// Get the current host
import host from 'ember-host-manager';

// Get all available hosts
import { hosts } from 'ember-host-manager'

1. Service

// adapters/application.js

export default DS.RESTAdapter.extend({
  // Inject the hostManager service
  hostManager: Ember.inject.service(),

  // hostManager.host has the config for the current host
  host: computed.readOnly('hostManager.host.apiHost'),
  namespace: computed.readOnly('hostManager.host.apiNamespace')
});

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.

export default Ember.Controller.extend({
  hostManager: Ember.inject.service(),

  init() {
    this._super(...arguments);

    const prodHost = this.get('hostManager').getHost('myapp.com');
    this.set('someProp', prodHost.get('someProp'));
  }
});

ember-host-manager's People

Contributors

offirgolan avatar ember-tomster avatar greenkeeperio-bot avatar

Stargazers

Ilya Radchenko avatar Mykola Basov avatar Luca D'Alessandro avatar Stefan Plattner avatar Brent Jubinville avatar Brandon Drake avatar

Watchers

 avatar David Baker avatar James Cloos avatar

ember-host-manager's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.