Complete Angel 2 examples
This commit is contained in:
parent
68affb6c7d
commit
7605329a3b
2 changed files with 24 additions and 19 deletions
38
README.md
38
README.md
|
@ -43,36 +43,42 @@ 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';
|
||||
|
||||
main() async {
|
||||
var hot = new HotReloader(createServer, [
|
||||
new Directory('config'),
|
||||
new Directory('lib'),
|
||||
new Directory('web'),
|
||||
new Directory('src'),
|
||||
'bin/server.dart',
|
||||
Uri.parse('some_file.dart'),
|
||||
new Directory('src'),
|
||||
'main.dart',
|
||||
Uri.parse('package:angel_hot/angel_hot.dart')
|
||||
]);
|
||||
|
||||
var server = await hot.startServer('127.0.0.1', 3000);
|
||||
print(
|
||||
'Hot server listening at http://${server.address.address}:${server.port}');
|
||||
await hot.startServer('127.0.0.1', 3000);
|
||||
}
|
||||
|
||||
Future<Angel> createServer() async {
|
||||
var app = new Angel();
|
||||
..injectSerializer(JSON.encode);
|
||||
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.post('/foo/bar', (req, res) async {
|
||||
var result = await someLengthyOperation();
|
||||
return {'status': result};
|
||||
});
|
||||
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;
|
||||
}
|
||||
```
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
import 'dart:async';
|
||||
import 'dart:io' show Directory;
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:angel_framework/angel_framework.dart';
|
||||
import 'package:angel_hot/angel_hot.dart';
|
||||
import 'package:dart2_constant/convert.dart';
|
||||
import 'package:dart2_constant/io.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'src/foo.dart';
|
||||
|
||||
|
|
Loading…
Reference in a new issue