platform/example/basic/main.dart

50 lines
1.2 KiB
Dart
Raw Normal View History

2017-06-06 12:07:59 +00:00
import 'dart:async';
2018-06-07 16:11:03 +00:00
import 'dart:io' show Directory;
2017-06-06 12:07:59 +00:00
import 'package:angel_framework/angel_framework.dart';
import 'package:angel_hot/angel_hot.dart';
2018-06-07 16:11:03 +00:00
import 'package:dart2_constant/convert.dart';
import 'package:dart2_constant/io.dart';
2017-10-19 18:32:41 +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, [
2017-06-12 19:26:45 +00:00
new Directory('src'),
2017-06-06 12:07:59 +00:00
new Directory('src'),
2018-06-07 16:11:03 +00:00
'main.dart',
2017-06-06 12:07:59 +00:00
Uri.parse('package:angel_hot/angel_hot.dart')
]);
2018-06-07 16:11:03 +00:00
var server = await hot.startServer('127.0.0.1', 3000);
print('Hot server listening at http://${server.address.address}:${server
.port}');
2017-06-06 12:07:59 +00:00
}
Future<Angel> createServer() async {
var app = new Angel();
app.lazyParseBodies = true;
2018-06-07 16:11:03 +00:00
app.serializer = json.encode;
2017-06-06 12:07:59 +00:00
2017-10-19 18:32:41 +00:00
// Edit this line, and then refresh the page in your browser!
2017-06-06 12:07:59 +00:00
app.get('/', {'hello': 'hot world!'});
app.get('/foo', new Foo(bar: 'baz'));
2017-10-19 18:32:41 +00:00
app.use(() => throw new AngelHttpException.notFound());
app.injectEncoders({
2018-06-07 16:11:03 +00:00
'gzip': gzip.encoder,
'deflate': zlib.encoder,
2017-10-19 18:32:41 +00:00
});
app.logger = new Logger('angel')
2018-06-07 16:11:03 +00:00
..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;
}