All Projects → juanpablob → angular-environment

juanpablob / angular-environment

Licence: MIT License
AngularJS Environment Plugin

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to angular-environment

envmnt
Environment variables utility functions.
Stars: ✭ 16 (-79.49%)
Mutual labels:  environment, environment-variables, environment-vars
envman
Manage your .env configuration easily
Stars: ✭ 20 (-74.36%)
Mutual labels:  environment-variables, environment-vars
rune
tool to query for tokens and passwords for use as environment variables
Stars: ✭ 13 (-83.33%)
Mutual labels:  environment, environment-variables
gatsby-plugin-dynamic-routes
Creating dynamic routes based on your environment and/or renaming existing routes
Stars: ✭ 14 (-82.05%)
Mutual labels:  environment, environment-variables
as-a
Runs a given command with additional environment settings for simple local development
Stars: ✭ 60 (-23.08%)
Mutual labels:  environment, environment-variables
DBEnvironmentConfiguration
Easily switch between iOS development environments/ configurations
Stars: ✭ 18 (-76.92%)
Mutual labels:  environment, environment-variables
env-dot-prop
♻️ Get, set, or delete nested properties of process.env using a dot path
Stars: ✭ 31 (-60.26%)
Mutual labels:  environment-variables, environment-vars
Oclazyload
Lazy load modules & components in AngularJS
Stars: ✭ 2,661 (+3311.54%)
Mutual labels:  angularjs, npm-package
aws-export-assume-profile
Export AWS profiles to your shell environment
Stars: ✭ 40 (-48.72%)
Mutual labels:  environment-variables, environment-vars
ionic-workflow-guide
Create a full and powerful worflow with Ionic (Unit Testing, Environment variables, Automatic documentation, Production App Server, Automatic deployment)
Stars: ✭ 46 (-41.03%)
Mutual labels:  environment-variables, environment-vars
ngx-env
Easily inject environment variables into your Angular applications
Stars: ✭ 73 (-6.41%)
Mutual labels:  environment, environment-variables
envyable
The simplest yaml to ENV config loader.
Stars: ✭ 78 (+0%)
Mutual labels:  environment-variables, environment-vars
ini
📝 Go INI config management. support multi file load, data override merge. parse ENV variable, parse variable reference. Dotenv file parse and loader. INI配置读取管理,支持多文件加载,数据覆盖合并, 解析ENV变量, 解析变量引用。DotEnv 解析加载
Stars: ✭ 72 (-7.69%)
Mutual labels:  environment, environment-variables
dotenvy
Speed up your production sites by ditching .env for key/value variable pairs as Apache, Nginx, and shell equivalents
Stars: ✭ 31 (-60.26%)
Mutual labels:  environment, environment-variables
secure-env
Env encryption tool that will help you prevent attacks from npm-malicious-packages.
Stars: ✭ 53 (-32.05%)
Mutual labels:  npm-package, environment-variables
dart environment config
Environment specific config generator for Dart and Flutter applications during CI/CD builds
Stars: ✭ 87 (+11.54%)
Mutual labels:  environment, environment-variables
Angular Translate
Translating your AngularJS 1.x apps
Stars: ✭ 4,414 (+5558.97%)
Mutual labels:  angularjs, npm-package
Angular Loading Feedback
Angular directive to indicate loads in app
Stars: ✭ 8 (-89.74%)
Mutual labels:  angularjs, npm-package
acre
Lightweight configurable environment management in Python
Stars: ✭ 20 (-74.36%)
Mutual labels:  environment, environment-variables
ts-dotenv
Strongly-typed environment variables for Node.js
Stars: ✭ 18 (-76.92%)
Mutual labels:  environment, environment-variables

AngularJS Environment Plugin

An useful plugin that allows you to set up different variables such as API Url, Sockets, Paths, etc, based on the context of script execution, which means you can set up (for example) different API endpoints depending if you are working on development, stage or production.

⚠️Warning / Heads up! Although this plugin works and it does the job, it has been out of development since a while now and it's no longer maintained other than people and community contributions / pull requests.

Installation

You can install this package either with npm or with bower.

bower

bower install angular-environment

npm

npm install angular-environment

Then add environment as a dependency for your app:

angular.module('yourApp', ['environment']);

Documentation

Sometimes, during the development of our applications, we need to use different variables depending on what context our application is running.

Let's say you're working on an application that handles an API, and you have a version of your API running locally on your computer or laptop for testing purposes. Besides, you have the final or in-production API running on a server. Certainly, the API endpoints are not the same in both environments, so, this plugin allows you to work with same variable for the same purpose but using different values depending on what context your application is running: development, stage or production.

Even better, you can execute code depending on the running context. In some cases you probably could need run pieces of code only for development environment and not in for production, or vice versa.

Said that, let's go to configure the plugin and learn how to use it.

Configuration

  • Once installed, inject the envServiceProvider into your Angular App config area.
  • Organize the environments as you wish under domains and vars objects.
  • You can use wildcards (*) to describe your domains, i.e.: *.domain.com.
  • As optional, you can set defaults variables under defaults object within vars, to catch not-defined variables in the environments.
  • Finally, in the same config area, you will need to check in which context your application is running, by adding envServiceProvider.check() which will automatically set the appropriate environment based on given domains.

Here's a full example:

angular.module('yourApp', ['environment']).
	config(function(envServiceProvider) {
		// set the domains and variables for each environment
		envServiceProvider.config({
			domains: {
				development: ['localhost', 'acme.dev.local'],
				production: ['acme.com', '*.acme.com', 'acme.dev.prod'],
				test: ['test.acme.com', 'acme.dev.test', 'acme.*.com'],
				// anotherStage: ['domain1', 'domain2']
			},
			vars: {
				development: {
					apiUrl: '//api.acme.dev.local/v1',
					staticUrl: '//static.acme.dev.local',
					// antoherCustomVar: 'lorem',
					// antoherCustomVar: 'ipsum'
				},
				test: {
					apiUrl: '//api.acme.dev.test/v1',
					staticUrl: '//static.acme.dev.test',
					// antoherCustomVar: 'lorem',
					// antoherCustomVar: 'ipsum'
				},
				production: {
					apiUrl: '//api.acme.com/v1',
					staticUrl: '//static.acme.com',
					// antoherCustomVar: 'lorem',
					// antoherCustomVar: 'ipsum'
				},
				// anotherStage: {
				// 	customVar: 'lorem',
				// 	customVar: 'ipsum'
				// },
				defaults: {
					apiUrl: '//api.default.com/v1',
					staticUrl: '//static.default.com'
				}
			}
		});

		// run the environment check, so the comprobation is made
		// before controllers and services are built
		envServiceProvider.check();
	});

Usage

In order to read the configured environment variables alongside your Angular App, you need to inject envService into your controllers or services:

controller('SomeController', ['$scope', 'envService', function($scope, envService) {
	// ...
}]);

get()

Returns a string with the current environment

var environment = envService.get(); // gets 'development'

set(string[environment])

Sets desired environment. This will overwrite the settled environment during the automatically check in Angular config process (see Configuration topic).

envService.set('production'); // will set 'production' as current environment

is(string[environment])

Returns true or false if the given environment matches with the current environment.

if (envService.is('production')) {
	// actually, the current environment is production
	// so, let's make some logic only for production environment
}
else {
	// we're not in production environment
}

read(string[var])

Returns the desired environment variable. If no argument is passed, this method will return all variables associated to the current environment.

var apiUrl = envService.read('apiUrl'); // gets '//localhost/api'

var allVars = envService.read(); // gets all variables configured under the current environment

If the desired variable passed as argument doesn't exists in the current environment, the plugin will check into defaults object.

To-Do

  • Support for adding domains with wildcards or regex.
  • Unit testing.
  • Support for protocols.

Support

To report bugs or request features, please visit the Issue Tracker.

Contributing to this plugin

Please feel free to contribute to the plugin with new issues, requests, unit tests, code fixes or new features. If you want to contribute with some code, create a feature branch and send your pull request.

License

Copyright 2015-2017, Juan Pablo Barrientos Lagos (juanpablob)

Licensed under The MIT License
Redistributions of files must retain the above copyright notice.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].