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 {
|
class Angel extends Routable {
|
||||||
ServerGenerator _serverGenerator = (address, port) async => await HttpServer
|
ServerGenerator _serverGenerator = (address, port) async => await HttpServer
|
||||||
.bind(address, port);
|
.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;
|
HttpServer httpServer;
|
||||||
God god = new God();
|
God god = new God();
|
||||||
|
@ -43,13 +44,20 @@ class Angel extends Routable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!res.willCloseItself) {
|
_finalizeResponse(request, res);
|
||||||
res.responseData.forEach((blob) => request.response.add(blob));
|
|
||||||
await request.response.close();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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;
|
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.
|
/// Applies an [AngelConfigurer] to this instance.
|
||||||
void configure(AngelConfigurer configurer) {
|
void configure(AngelConfigurer configurer) {
|
||||||
configurer(this);
|
configurer(this);
|
||||||
|
@ -114,12 +129,15 @@ class Angel extends Routable {
|
||||||
}, onError: onError);
|
}, onError: onError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Responds to a 404.
|
||||||
|
RequestHandler on404 = (req, res) => res.write("404 Not Found");
|
||||||
|
|
||||||
/// Handles a server error.
|
/// Handles a server error.
|
||||||
var onError = (e, [StackTrace stackTrace]) {
|
onError(e, [StackTrace stackTrace]) {
|
||||||
stderr.write(e.toString());
|
stderr.write(e.toString());
|
||||||
if (stackTrace != null)
|
if (stackTrace != null)
|
||||||
stderr.write(stackTrace.toString());
|
stderr.write(stackTrace.toString());
|
||||||
};
|
}
|
||||||
|
|
||||||
Angel() : super() {}
|
Angel() : super() {}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
name: angel_framework
|
name: angel_framework
|
||||||
version: 0.0.0-dev.1
|
version: 0.0.0-dev.2
|
||||||
description: Core libraries for the Angel framework.
|
description: Core libraries for the Angel framework.
|
||||||
author: Tobe O <thosakwe@gmail.com>
|
author: Tobe O <thosakwe@gmail.com>
|
||||||
homepage: https://github.com/angel-dart/angel_framework
|
homepage: https://github.com/angel-dart/angel_framework
|
||||||
|
|
Loading…
Reference in a new issue