platform/README.md

70 lines
1.9 KiB
Markdown
Raw Normal View History

2016-04-22 01:17:31 +00:00
# Angel Configuration
2016-11-23 20:51:20 +00:00
![version 1.0.1+6](https://img.shields.io/badge/version-1.0.1+6-red.svg)
![build status](https://travis-ci.org/angel-dart/configuration.svg)
2016-09-19 20:31:32 +00:00
Isomorphic 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
2016-09-19 20:33:01 +00:00
for a `config/default.yaml` file. If it is found, configuration from it is loaded into `angel.properties`.
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:
2016-09-19 11:19:48 +00:00
angel_configuration: ^1.0.0-dev
2016-09-19 11:19:22 +00:00
```
2016-04-22 01:17:31 +00:00
# Usage
2016-09-19 20:31:32 +00:00
**Server-side**
2016-04-22 01:17:31 +00:00
```dart
import 'dart:io';
import 'package:angel_framework/angel_framework.dart';
import 'package:angel_configuration/angel_configuration.dart';
main() async {
Angel angel = new Angel();
2016-09-19 20:31:32 +00:00
angel.configure(loadConfigurationFile()); // It's that easy!
2016-11-23 20:51:20 +00:00
app.get('/foo', (Configuration config) {
return config.some_key;
});
2016-04-22 01:17:31 +00:00
}
```
`loadConfigurationFile` also accepts a `sourceDirectory` or `overrideEnvironmentName` parameter.
The former will allow you to search in a directory other than `config`, and the latter lets you
2016-09-19 11:19:22 +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
**In the Browser**
You can easily load configuration values within your client-side app,
and they will be automatically replaced by a Barback transformer.
2016-09-19 20:38:29 +00:00
In your `pubspec.yaml`:
```yaml
transformers:
- angel_configuration
```
In your app:
2016-09-19 20:31:32 +00:00
```dart
import 'package:angel_configuration/browser.dart';
main() async {
print(config("some_key.other.nested_key"));
}
```
2016-09-19 20:33:01 +00:00
You can also provide a `dir` or `env` argument, corresponding to
the ones on the server-side.