项目作者: ampatspell

项目描述 :
Ember.js dotenv for FastBoot
高级语言: JavaScript
项目地址: git://github.com/ampatspell/ember-cli-fastboot-dotenv.git
创建时间: 2017-10-05T12:03:45Z
项目社区:https://github.com/ampatspell/ember-cli-fastboot-dotenv

开源协议:MIT License

下载


ember-cli-fastboot-dotenv

ember-cli-dotenv-like addon for Ember.js for FastBoot which allows to use environment variables passed to FastBoot server in runtime.

Use .env file for development and production defaults.

See Ohne Zeit as an example from which the following info is extracted from.

  1. // .env
  2. COUCH_URL=http://127.0.0.1:5984
  3. DATABASE_NAME=ohne-zeit
  4. CHANGES_FEED=event-source

Set allowed keys in ember-cli-build:

  1. const EmberApp = require('ember-cli/lib/broccoli/ember-app');
  2. module.exports = function(defaults) {
  3. let app = new EmberApp(defaults, {
  4. 'ember-cli-fastboot-dotenv': {
  5. keys: [ 'COUCH_URL', 'DATABASE_NAME', 'CHANGES_FEED' ]
  6. }
  7. });
  8. return app.toTree();
  9. };

Build your app without .env or keep it for defaults.

  1. $ ember build -prod
  2. $ cd dist
  3. $ npm install

Override .env defaults with environment variables when running in FastBoot:

  1. // fastboot-server.js
  2. const app = express();
  3. app.get('/*', fastboot('./dist'));
  4. app.listen(3000);
  1. $ COUCH_URL=http://server:5984 ./fastboot-server.js

Configuration lookup in the app (FastBoot and Browser)

  1. // app/instance-initializers/store.js
  2. export default {
  3. name: 'app:store',
  4. after: 'ember-cli-fastboot-dotenv',
  5. initialize(app) {
  6. let dotenv = app.lookup('service:dotenv');
  7. let {
  8. couchURL,
  9. databaseName,
  10. changesFeed
  11. } = dotenv.getProperties('couchURL', 'databaseName', 'changesFeed');
  12. // ...
  13. }
  14. };