2017-09-25 13:50:56 +00:00
|
|
|
# configuration
|
2016-11-23 20:51:20 +00:00
|
|
|
|
2017-06-14 18:48:13 +00:00
|
|
|
[![Pub](https://img.shields.io/pub/v/angel_configuration.svg)](https://pub.dartlang.org/packages/angel_configuration)
|
2017-06-14 18:48:27 +00:00
|
|
|
[![build status](https://travis-ci.org/angel-dart/configuration.svg)](https://travis-ci.org/angel-dart/configuration)
|
2016-11-23 20:51:20 +00:00
|
|
|
|
2017-06-14 18:48:13 +00:00
|
|
|
Automatic YAML configuration loader for Angel.
|
2016-04-22 01:17:31 +00:00
|
|
|
|
|
|
|
# About
|
|
|
|
Any web app needs different configuration for development and production. This plugin will search
|
2017-09-25 13:50:56 +00:00
|
|
|
for a `config/default.yaml` file. If it is found, configuration from it is loaded into `app.configuration`.
|
2016-04-22 01:17:31 +00:00
|
|
|
Then, it will look for a `config/$ANGEL_ENV` file. (i.e. config/development.yaml). If this found, all of its
|
|
|
|
configuration be loaded, and will override anything loaded from the `default.yaml` file. This allows for your
|
|
|
|
app to work under different conditions without you re-coding anything. :)
|
|
|
|
|
|
|
|
# Installation
|
|
|
|
In `pubspec.yaml`:
|
|
|
|
|
2016-09-19 11:19:22 +00:00
|
|
|
```yaml
|
|
|
|
dependencies:
|
2018-12-31 15:42:09 +00:00
|
|
|
angel_configuration: ^2.0.0
|
2016-09-19 11:19:22 +00:00
|
|
|
```
|
2016-04-22 01:17:31 +00:00
|
|
|
|
|
|
|
# Usage
|
|
|
|
|
2017-06-14 18:48:13 +00:00
|
|
|
**Example Configuration**
|
|
|
|
```yaml
|
|
|
|
# Define normal YAML objects
|
|
|
|
some_key: foo
|
|
|
|
this_is_a_map:
|
|
|
|
a_string: "string"
|
|
|
|
another_string: "string"
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
You can also load configuration from the environment:
|
|
|
|
```yaml
|
|
|
|
# Loaded from the environment
|
|
|
|
system_path: $PATH
|
|
|
|
```
|
|
|
|
|
|
|
|
If a `.env` file is present in your configuration directory, then it will be loaded before
|
|
|
|
applying YAML configuration.
|
|
|
|
|
2016-09-19 20:31:32 +00:00
|
|
|
**Server-side**
|
2017-09-25 13:50:56 +00:00
|
|
|
Call `configuration()`. The loaded configuration will be available in your application's
|
2018-08-21 19:08:32 +00:00
|
|
|
`configuration` map.
|
2016-04-22 01:17:31 +00:00
|
|
|
|
2017-09-25 13:50:56 +00:00
|
|
|
`configuration` also accepts a `sourceDirectory` or `overrideEnvironmentName` parameter.
|
2016-04-22 01:17:31 +00:00
|
|
|
The former will allow you to search in a directory other than `config`, and the latter lets you
|
2017-06-14 18:48:13 +00:00
|
|
|
override `$ANGEL_ENV` by specifying a specific configuration name to look for (i.e. `production`).
|
2016-09-19 20:31:32 +00:00
|
|
|
|
2017-08-16 00:29:13 +00:00
|
|
|
This package uses
|
|
|
|
[`package:merge_map`](https://github.com/thosakwe/merge_map)
|
|
|
|
internally, so existing configurations can be deeply merged.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
# default.yaml
|
|
|
|
foo:
|
|
|
|
bar: baz
|
|
|
|
quux: hello
|
|
|
|
|
|
|
|
# production.yaml
|
|
|
|
foo:
|
|
|
|
quux: goodbye
|
|
|
|
yellow: submarine
|
|
|
|
|
|
|
|
# Propagates to:
|
|
|
|
foo:
|
|
|
|
bar: baz
|
|
|
|
quux: goodbye
|
|
|
|
yellow: submarine
|
2018-07-12 16:40:54 +00:00
|
|
|
```
|