platform/packages/configuration/README.md

88 lines
2.5 KiB
Markdown
Raw Normal View History

2021-07-08 05:23:02 +00:00
# Angel3 Configuration Loader
2021-09-25 06:32:32 +00:00
![Pub Version (including pre-releases)](https://img.shields.io/pub/v/angel3_configuration?include_prereleases)
2021-05-14 11:27:54 +00:00
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
2024-07-07 15:02:49 +00:00
[![Discord](https://img.shields.io/discord/1060322353214660698)](https://discord.gg/3X6bxTUdCM)
2023-12-25 03:45:10 +00:00
[![License](https://img.shields.io/github/license/dart-backend/angel)](https://github.com/dart-backend/angel/tree/master/packages/configuration/LICENSE)
2016-11-23 20:51:20 +00:00
2021-07-08 05:23:02 +00:00
Automatic YAML configuration loader for [Angel3 framework](https://pub.dev/packages/angel3)
2016-11-23 20:51:20 +00:00
2021-07-08 05:23:02 +00:00
## About
2016-04-22 01:17:31 +00:00
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. :)
2021-07-08 05:23:02 +00:00
## Installation
2016-04-22 01:17:31 +00:00
In `pubspec.yaml`:
2016-09-19 11:19:22 +00:00
```yaml
dependencies:
2022-02-24 00:32:54 +00:00
angel3_configuration: ^6.0.0
2016-09-19 11:19:22 +00:00
```
2016-04-22 01:17:31 +00:00
2021-07-08 05:23:02 +00:00
## Usage
Example Configuration
2016-04-22 01:17:31 +00:00
2017-06-14 18:48:13 +00:00
```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:
2021-07-08 05:23:02 +00:00
2017-06-14 18:48:13 +00:00
```yaml
# Loaded from the environment
system_path: $PATH
```
If a `.env` file is present in your configuration directory (i.e. `config/.env`), then it will be loaded before
2017-06-14 18:48:13 +00:00
applying YAML configuration.
You can also include values from one file into another:
2021-07-08 05:23:02 +00:00
```yaml
_include:
- "./include-prod.yaml"
- "./include-misc.yaml"
_include: "just-one-file.yaml"
```
2016-09-19 20:31:32 +00:00
**Server-side**
2021-07-08 05:23:02 +00:00
Call `configuration()`. The loaded configuration will be available in your application's `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
2021-07-08 05:23:02 +00:00
This package uses [`package:angel3_merge_map`](https://pub.dev/packages/angel3_merge_map)
2017-08-16 00:29:13 +00:00
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
```