2021-05-15 13:17:18 +00:00
|
|
|
# angel3_hot
|
2021-06-14 04:07:28 +00:00
|
|
|
[](https://pub.dartlang.org/packages/angel3_hot)
|
2021-05-15 13:17:18 +00:00
|
|
|
[](https://dart.dev/null-safety)
|
|
|
|
[](https://gitter.im/angel_dart/discussion)
|
|
|
|
|
|
|
|
[](https://github.com/dukefirehawk/angel/tree/angel3/packages/hot/LICENSE)
|
2017-06-06 12:07:59 +00:00
|
|
|
|
2018-10-02 16:13:47 +00:00
|
|
|

|
|
|
|
|
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`.
|
|
|
|
|
2021-05-15 13:17:18 +00:00
|
|
|
This package only works with the [Angel framework](https://github.com/dukefirehawk/angel/tree/angel3).
|
2017-06-06 12:07:59 +00:00
|
|
|
|
|
|
|
# Installation
|
|
|
|
In your `pubspec.yaml`:
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
dependencies:
|
2021-05-15 13:17:18 +00:00
|
|
|
angel3_framework: ^4.0.0
|
|
|
|
angel3_hot: ^4.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';
|
2018-11-02 20:30:08 +00:00
|
|
|
import 'package:logging/logging.dart';
|
2017-06-06 12:07:59 +00:00
|
|
|
import 'src/foo.dart';
|
|
|
|
|
|
|
|
main() async {
|
|
|
|
var hot = new HotReloader(createServer, [
|
|
|
|
new Directory('src'),
|
2018-11-02 20:30:08 +00:00
|
|
|
new Directory('src'),
|
|
|
|
'main.dart',
|
2017-06-06 12:07:59 +00:00
|
|
|
Uri.parse('package:angel_hot/angel_hot.dart')
|
|
|
|
]);
|
2018-11-02 20:30:08 +00:00
|
|
|
await hot.startServer('127.0.0.1', 3000);
|
2017-06-06 12:07:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Future<Angel> createServer() async {
|
2018-11-02 20:30:08 +00:00
|
|
|
var app = new Angel()..serializer = json.encode;
|
2017-06-06 12:07:59 +00:00
|
|
|
|
2018-11-02 20:30:08 +00:00
|
|
|
// Edit this line, and then refresh the page in your browser!
|
2018-11-02 20:27:05 +00:00
|
|
|
app.get('/', (req, res) => {'hello': 'hot world!'});
|
2018-11-02 20:30:08 +00:00
|
|
|
app.get('/foo', (req, res) => new Foo(bar: 'baz'));
|
2017-06-06 12:07:59 +00:00
|
|
|
|
2018-11-02 20:27:05 +00:00
|
|
|
app.fallback((req, res) => throw new AngelHttpException.notFound());
|
2018-11-02 20:30:08 +00:00
|
|
|
|
|
|
|
app.encoders.addAll({
|
|
|
|
'gzip': gzip.encoder,
|
|
|
|
'deflate': zlib.encoder,
|
|
|
|
});
|
|
|
|
|
|
|
|
app.logger = new Logger('angel')
|
|
|
|
..onRecord.listen((rec) {
|
|
|
|
print(rec);
|
|
|
|
if (rec.error != null) {
|
|
|
|
print(rec.error);
|
|
|
|
print(rec.stackTrace);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-06-06 12:07:59 +00:00
|
|
|
return app;
|
|
|
|
}
|
2018-11-02 20:27:05 +00:00
|
|
|
```
|