Restructure example, forcibly close logger on reload
This commit is contained in:
parent
f8a6cab236
commit
6dd28ed151
3 changed files with 39 additions and 35 deletions
|
@ -1,44 +1,14 @@
|
|||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:angel_framework/angel_framework.dart';
|
||||
import 'package:angel_hot/angel_hot.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'src/foo.dart';
|
||||
import 'server.dart';
|
||||
|
||||
main() async {
|
||||
var hot = new HotReloader(createServer, [
|
||||
new Directory('src'),
|
||||
new Directory('src'),
|
||||
'main.dart',
|
||||
Platform.script,
|
||||
'server.dart',
|
||||
// Also allowed: Platform.script,
|
||||
Uri.parse('package:angel_hot/angel_hot.dart')
|
||||
]);
|
||||
await hot.startServer('127.0.0.1', 3000);
|
||||
}
|
||||
|
||||
Future<Angel> createServer() async {
|
||||
var app = new Angel()..serializer = json.encode;
|
||||
|
||||
// Edit this line, and then refresh the page in your browser!
|
||||
app.get('/', (req, res) => {'hello': 'hot world!'});
|
||||
app.get('/foo', (req, res) => new Foo(bar: 'baz'));
|
||||
|
||||
app.fallback((req, res) => throw new AngelHttpException.notFound());
|
||||
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
||||
return app;
|
||||
}
|
||||
|
|
32
example/server.dart
Normal file
32
example/server.dart
Normal file
|
@ -0,0 +1,32 @@
|
|||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:angel_framework/angel_framework.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'src/foo.dart';
|
||||
|
||||
Future<Angel> createServer() async {
|
||||
var app = new Angel()..serializer = json.encode;
|
||||
hierarchicalLoggingEnabled = true;
|
||||
|
||||
// Edit this line, and then refresh the page in your browser!
|
||||
app.get('/', (req, res) => {'hello': 'hot world!'});
|
||||
app.get('/foo', (req, res) => new Foo(bar: 'baz'));
|
||||
|
||||
app.fallback((req, res) => throw new AngelHttpException.notFound());
|
||||
|
||||
app.encoders.addAll({
|
||||
'gzip': gzip.encoder,
|
||||
'deflate': zlib.encoder,
|
||||
});
|
||||
|
||||
app.logger = new Logger.detached('angel')
|
||||
..onRecord.listen((rec) {
|
||||
print(rec);
|
||||
if (rec.error != null) {
|
||||
print(rec.error);
|
||||
print(rec.stackTrace);
|
||||
}
|
||||
});
|
||||
|
||||
return app;
|
||||
}
|
|
@ -317,8 +317,10 @@ class HotReloader {
|
|||
}
|
||||
}
|
||||
|
||||
await Future.forEach(
|
||||
_server.app.shutdownHooks, _server.app.configure);
|
||||
// await Future.forEach(
|
||||
// _server.app.shutdownHooks, _server.app.configure);
|
||||
await _server.app.close();
|
||||
_server.app.logger?.clearListeners();
|
||||
} catch (_) {
|
||||
// Fail silently...
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue