2017-06-06 12:07:59 +00:00
|
|
|
import 'dart:async';
|
|
|
|
import 'dart:convert';
|
|
|
|
import 'dart:io';
|
|
|
|
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'),
|
|
|
|
'server.dart',
|
|
|
|
Uri.parse('package:angel_hot/angel_hot.dart')
|
|
|
|
]);
|
|
|
|
var server = await hot.startServer(InternetAddress.LOOPBACK_IP_V4, 3000);
|
|
|
|
print(
|
|
|
|
'Hot server listening at http://${server.address.address}:${server.port}');
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<Angel> createServer() async {
|
|
|
|
var app = new Angel();
|
|
|
|
|
|
|
|
app.lazyParseBodies = true;
|
|
|
|
app.injectSerializer(JSON.encode);
|
|
|
|
|
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({
|
|
|
|
'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;
|
|
|
|
}
|