dev.2
This commit is contained in:
parent
d4d5678f64
commit
f993155c04
2 changed files with 26 additions and 8 deletions
|
@ -10,7 +10,8 @@ typedef AngelConfigurer(Angel app);
|
|||
class Angel extends Routable {
|
||||
ServerGenerator _serverGenerator = (address, port) async => await HttpServer
|
||||
.bind(address, port);
|
||||
var viewGenerator = (String view, {Map data}) => "No view engine has been configured yet.";
|
||||
var viewGenerator = (String view,
|
||||
{Map data}) => "No view engine has been configured yet.";
|
||||
|
||||
HttpServer httpServer;
|
||||
God god = new God();
|
||||
|
@ -43,13 +44,20 @@ class Angel extends Routable {
|
|||
}
|
||||
}
|
||||
|
||||
if (!res.willCloseItself) {
|
||||
res.responseData.forEach((blob) => request.response.add(blob));
|
||||
await request.response.close();
|
||||
}
|
||||
_finalizeResponse(request, res);
|
||||
});
|
||||
});
|
||||
|
||||
router.defaultStream.listen((HttpRequest request) async {
|
||||
RequestContext req = await RequestContext.from(
|
||||
request, {}, this,
|
||||
null);
|
||||
ResponseContext res = await ResponseContext.from(
|
||||
request.response, this);
|
||||
on404(req, res);
|
||||
_finalizeResponse(request, res);
|
||||
});
|
||||
|
||||
return server;
|
||||
}
|
||||
|
||||
|
@ -102,6 +110,13 @@ class Angel extends Routable {
|
|||
}
|
||||
}
|
||||
|
||||
_finalizeResponse(HttpRequest request, ResponseContext res) async {
|
||||
if (!res.willCloseItself) {
|
||||
res.responseData.forEach((blob) => request.response.add(blob));
|
||||
await request.response.close();
|
||||
}
|
||||
}
|
||||
|
||||
/// Applies an [AngelConfigurer] to this instance.
|
||||
void configure(AngelConfigurer configurer) {
|
||||
configurer(this);
|
||||
|
@ -114,12 +129,15 @@ class Angel extends Routable {
|
|||
}, onError: onError);
|
||||
}
|
||||
|
||||
/// Responds to a 404.
|
||||
RequestHandler on404 = (req, res) => res.write("404 Not Found");
|
||||
|
||||
/// Handles a server error.
|
||||
var onError = (e, [StackTrace stackTrace]) {
|
||||
onError(e, [StackTrace stackTrace]) {
|
||||
stderr.write(e.toString());
|
||||
if (stackTrace != null)
|
||||
stderr.write(stackTrace.toString());
|
||||
};
|
||||
}
|
||||
|
||||
Angel() : super() {}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
name: angel_framework
|
||||
version: 0.0.0-dev.1
|
||||
version: 0.0.0-dev.2
|
||||
description: Core libraries for the Angel framework.
|
||||
author: Tobe O <thosakwe@gmail.com>
|
||||
homepage: https://github.com/angel-dart/angel_framework
|
||||
|
|
Loading…
Reference in a new issue