2017-06-06 09:19:32 +00:00
|
|
|
# hot
|
2017-06-12 19:26:45 +00:00
|
|
|
[![Pub](https://img.shields.io/pub/v/angel_hot.svg)](https://pub.dartlang.org/packages/angel_hot)
|
2017-06-06 12:07:59 +00:00
|
|
|
|
2018-10-02 16:13:47 +00:00
|
|
|
![Screenshot of terminal](screenshots/screenshot.png)
|
|
|
|
|
2017-06-06 12:07:59 +00:00
|
|
|
Supports *hot reloading* of Angel servers on file changes. This is faster and
|
|
|
|
more reliable than merely reactively restarting a `Process`.
|
|
|
|
|
|
|
|
This package only works with the [Angel framework](https://github.com/angel-dart/angel).
|
|
|
|
|
|
|
|
# Installation
|
|
|
|
In your `pubspec.yaml`:
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
dependencies:
|
2018-11-02 20:27:05 +00:00
|
|
|
angel_framework: ^2.0.0-alpha
|
|
|
|
angel_hot: ^2.0.0
|
2017-06-06 12:07:59 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
# Usage
|
|
|
|
This package is dependent on the Dart VM service, so you *must* run
|
2018-11-02 20:27:05 +00:00
|
|
|
Dart with the `--observe` (or `--enable-vm-service`) argument!!!
|
2017-06-06 12:07:59 +00:00
|
|
|
|
|
|
|
Usage is fairly simple. Pass a function that creates an `Angel` server, along with a collection of paths
|
|
|
|
to watch, to the `HotReloader` constructor. The rest is history!!!
|
|
|
|
|
|
|
|
The recommended pattern is to only use hot-reloading in your application entry point. Create your `Angel` instance
|
2018-10-02 16:13:47 +00:00
|
|
|
within a separate function, conventionally named `createServer`.
|
|
|
|
|
2018-11-02 20:27:05 +00:00
|
|
|
**Using this in production mode is not recommended, unless you are
|
|
|
|
specifically intending for a "hot code push" in production..**
|
2017-06-06 12:07:59 +00:00
|
|
|
|
|
|
|
You can watch:
|
|
|
|
* Files
|
|
|
|
* Directories
|
|
|
|
* Globs
|
|
|
|
* URI's
|
|
|
|
* `package:` URI's
|
|
|
|
|
|
|
|
```dart
|
|
|
|
import 'dart:async';
|
|
|
|
import 'dart:convert';
|
|
|
|
import 'dart:io';
|
|
|
|
import 'package:angel_framework/angel_framework.dart';
|
|
|
|
import 'package:angel_hot/angel_hot.dart';
|
|
|
|
import 'src/foo.dart';
|
|
|
|
|
|
|
|
main() async {
|
|
|
|
var hot = new HotReloader(createServer, [
|
|
|
|
new Directory('config'),
|
|
|
|
new Directory('lib'),
|
|
|
|
new Directory('web'),
|
|
|
|
new Directory('src'),
|
|
|
|
'bin/server.dart',
|
|
|
|
Uri.parse('some_file.dart'),
|
|
|
|
Uri.parse('package:angel_hot/angel_hot.dart')
|
|
|
|
]);
|
|
|
|
|
2018-11-02 20:27:05 +00:00
|
|
|
var server = await hot.startServer('127.0.0.1', 3000);
|
2017-06-06 12:07:59 +00:00
|
|
|
print(
|
|
|
|
'Hot server listening at http://${server.address.address}:${server.port}');
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<Angel> createServer() async {
|
|
|
|
var app = new Angel();
|
2018-11-02 20:27:05 +00:00
|
|
|
..injectSerializer(JSON.encode);
|
2017-06-06 12:07:59 +00:00
|
|
|
|
2018-11-02 20:27:05 +00:00
|
|
|
app.get('/', (req, res) => {'hello': 'hot world!'});
|
2017-06-06 12:07:59 +00:00
|
|
|
|
|
|
|
app.post('/foo/bar', (req, res) async {
|
|
|
|
var result = await someLengthyOperation();
|
|
|
|
return {'status': result};
|
|
|
|
});
|
|
|
|
|
2018-11-02 20:27:05 +00:00
|
|
|
app.fallback((req, res) => throw new AngelHttpException.notFound());
|
2017-06-06 12:07:59 +00:00
|
|
|
return app;
|
|
|
|
}
|
2018-11-02 20:27:05 +00:00
|
|
|
```
|