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);
|
2018-10-02 15:08:23 +00:00
|
|
|
print(
|
|
|
|
'Hot server listening at http://${server.address.address}:${server.port}');
|
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;
|
|
|
|
}
|