platform/example/main.dart

45 lines
1.1 KiB
Dart
Raw Normal View History

2017-06-06 12:07:59 +00:00
import 'dart:async';
2018-11-02 20:30:08 +00:00
import 'dart:convert';
import 'dart:io';
2017-06-06 12:07:59 +00:00
import 'package:angel_framework/angel_framework.dart';
import 'package:angel_hot/angel_hot.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',
2018-11-09 20:39:34 +00:00
Platform.script,
2017-06-06 12:07:59 +00:00
Uri.parse('package:angel_hot/angel_hot.dart')
]);
2018-10-02 16:13:47 +00:00
await hot.startServer('127.0.0.1', 3000);
2017-06-06 12:07:59 +00:00
}
Future<Angel> createServer() async {
2018-10-02 15:08:23 +00:00
var app = new Angel()..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!
2018-10-02 15:08:23 +00:00
app.get('/', (req, res) => {'hello': 'hot world!'});
app.get('/foo', (req, res) => new Foo(bar: 'baz'));
2017-06-06 12:07:59 +00:00
2018-10-02 15:08:23 +00:00
app.fallback((req, res) => throw new AngelHttpException.notFound());
2017-10-19 18:32:41 +00:00
2018-10-02 15:08:23 +00:00
app.encoders.addAll({
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;
}