This commit is contained in:
Tobe O 2017-10-19 14:32:41 -04:00
parent 18c06142a9
commit 1623e92e94
5 changed files with 25 additions and 24 deletions

View file

@ -5,10 +5,6 @@
<excludeFolder url="file://$MODULE_DIR$/.pub" />
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
<excludeFolder url="file://$MODULE_DIR$/build" />
<excludeFolder url="file://$MODULE_DIR$/example/basic/packages" />
<excludeFolder url="file://$MODULE_DIR$/example/basic/src/packages" />
<excludeFolder url="file://$MODULE_DIR$/example/packages" />
<excludeFolder url="file://$MODULE_DIR$/packages" />
<excludeFolder url="file://$MODULE_DIR$/temp" />
<excludeFolder url="file://$MODULE_DIR$/tmp" />
</content>

View file

@ -11,7 +11,6 @@ In your `pubspec.yaml`:
```yaml
dependencies:
angel_framework: ^1.0.0
angel_hot: ^1.0.0
```

View file

@ -1,10 +1,9 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:angel_compress/angel_compress.dart';
import 'package:angel_diagnostics/angel_diagnostics.dart';
import 'package:angel_framework/angel_framework.dart';
import 'package:angel_hot/angel_hot.dart';
import 'package:logging/logging.dart';
import 'src/foo.dart';
main() async {
@ -20,19 +19,30 @@ main() async {
}
Future<Angel> createServer() async {
// Max speed???
var app = new Angel();
app.lazyParseBodies = true;
app.injectSerializer(JSON.encode);
// Edit this line, and then refresh the page in your browser!
app.get('/', {'hello': 'hot world!'});
app.get('/foo', new Foo(bar: 'baz'));
app.after.add(() => throw new AngelHttpException.notFound());
app.use(() => throw new AngelHttpException.notFound());
app.injectEncoders({
'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);
}
});
app.responseFinalizers.add(gzip());
//await app.configure(cacheResponses());
await app.configure(logRequests());
return app;
}

View file

@ -11,9 +11,7 @@ import 'package:html_builder/html_builder.dart';
import 'package:vm_service_client/vm_service_client.dart';
import 'package:watcher/watcher.dart';
/// A typedef over a function that returns a fresh [Angel] instance, whether synchronously or asynchronously.
typedef FutureOr<Angel> AngelGenerator();
/// A utility class that watches the filesystem for changes, and starts new instances of an Angel server.
class HotReloader {
VMServiceClient _client;
final StreamController<WatchEvent> _onChange =
@ -25,7 +23,7 @@ class HotReloader {
Duration _timeout;
/// Invoked to load a new instance of [Angel] on file changes.
final AngelGenerator generator;
final FutureOr<Angel> Function() generator;
/// Fires whenever a file change. You might consider using this to trigger
/// page reloads in a client.
@ -105,7 +103,7 @@ class HotReloader {
Future<Angel> _generateServer() async {
var s = await generator() as Angel;
await Future.forEach(s.justBeforeStart, s.configure);
await Future.forEach(s.startupHooks, s.configure);
s.optimizeForProduction();
return s;
}
@ -214,14 +212,14 @@ class HotReloader {
for (var client in ws.clients) {
try {
client.io.close(WebSocketStatus.GOING_AWAY);
await client.close(WebSocketStatus.GOING_AWAY);
} catch (e) {
stderr.writeln(
'Couldn\'t close WebSocket from session #${client.request.session.id}: $e');
}
}
Future.forEach(old.justBeforeStop, old.configure);
Future.forEach(old.shutdownHooks, old.configure);
});
}

View file

@ -1,21 +1,19 @@
name: angel_hot
description: Supports hot reloading of Angel servers on file changes.
version: 1.0.1
version: 1.1.0-alpha
author: Tobe O <thosakwe@gmail.com>
homepage: https://github.com/angel-dart/hot
environment:
sdk: ">=1.19.0"
dependencies:
angel_framework: ^1.0.0-dev
angel_websocket: ^1.0.0
angel_framework: ^1.1.0-alpha
angel_websocket: ^1.1.0-alpha
html_builder: ^1.0.0
vm_service_client:
git:
url: git://github.com/BlackHC/vm_service_client.git
ref: reload_sources_poc
dev_dependencies:
angel_compress: ^1.0.0
angel_diagnostics: ^1.0.0
angel_test: ^1.0.0
http: ^0.11.3
test: ^0.12.15