+1
This commit is contained in:
parent
9df72be406
commit
d0e765dcd4
4 changed files with 35 additions and 10 deletions
|
@ -1,3 +1,6 @@
|
|||
# 2.0.2+1
|
||||
* Fix a bug in the implementation of `Controller.applyRoutes`.
|
||||
|
||||
# 2.0.2
|
||||
* Make `ResponseContext` *explicitly* implement `StreamConsumer` (though technically it already did???)
|
||||
* Split `Controller.configureServer` to create `Controller.applyRoutes`.
|
||||
|
|
|
@ -25,8 +25,9 @@ class Controller {
|
|||
|
||||
Controller({this.injectSingleton = true});
|
||||
|
||||
/// Applies routes, DI, and other configuration to an [app].
|
||||
@mustCallSuper
|
||||
Future configureServer(Angel app) {
|
||||
FutureOr<void> configureServer(Angel app) {
|
||||
_app = app;
|
||||
|
||||
if (injectSingleton != false) {
|
||||
|
@ -35,13 +36,13 @@ class Controller {
|
|||
}
|
||||
}
|
||||
|
||||
return applyRoutes(app, app.container.reflector).then((name) {
|
||||
app.controllers[name] = this;
|
||||
});
|
||||
var name = applyRoutes(app, app.container.reflector);
|
||||
app.controllers[name] = this;
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Applies the routes from this [Controller] to some [router].
|
||||
Future<String> applyRoutes(Router router, Reflector reflector) {
|
||||
String applyRoutes(Router router, Reflector reflector) {
|
||||
// Load global expose decl
|
||||
var classMirror = reflector.reflectClass(this.runtimeType);
|
||||
Expose exposeDecl = findExpose(reflector);
|
||||
|
@ -59,16 +60,17 @@ class Controller {
|
|||
final handlers = <RequestHandler>[]
|
||||
..addAll(exposeDecl.middleware)
|
||||
..addAll(middleware);
|
||||
final routeBuilder = _routeBuilder(instanceMirror, routable, handlers);
|
||||
final routeBuilder =
|
||||
_routeBuilder(reflector, instanceMirror, routable, handlers);
|
||||
classMirror.declarations.forEach(routeBuilder);
|
||||
configureRoutes(routable);
|
||||
|
||||
// Return the name.
|
||||
return Future.value(
|
||||
exposeDecl.as?.isNotEmpty == true ? exposeDecl.as : typeMirror.name);
|
||||
return exposeDecl.as?.isNotEmpty == true ? exposeDecl.as : typeMirror.name;
|
||||
}
|
||||
|
||||
void Function(ReflectedDeclaration) _routeBuilder(
|
||||
Reflector reflector,
|
||||
ReflectedInstance instanceMirror,
|
||||
Routable routable,
|
||||
Iterable<RequestHandler> handlers) {
|
||||
|
@ -109,7 +111,7 @@ class Controller {
|
|||
return;
|
||||
}
|
||||
|
||||
var injection = preInject(reflectedMethod, app.container.reflector);
|
||||
var injection = preInject(reflectedMethod, reflector);
|
||||
|
||||
if (exposeDecl?.allowNull?.isNotEmpty == true) {
|
||||
injection.optional?.addAll(exposeDecl.allowNull);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
name: angel_framework
|
||||
version: 2.0.2
|
||||
version: 2.0.2+1
|
||||
description: A high-powered HTTP server with dependency injection, routing and much more.
|
||||
author: Tobe O <thosakwe@gmail.com>
|
||||
homepage: https://github.com/angel-dart/angel_framework
|
||||
|
|
|
@ -70,6 +70,13 @@ main() {
|
|||
// Using mountController<T>();
|
||||
await app.mountController<TodoController>();
|
||||
|
||||
// Place controller in group...
|
||||
app.group('/ctrl_group', (router) {
|
||||
app.container
|
||||
.make<TodoController>()
|
||||
.applyRoutes(router, app.container.reflector);
|
||||
});
|
||||
|
||||
print(app.controllers);
|
||||
app.dumpTree();
|
||||
|
||||
|
@ -129,6 +136,19 @@ main() {
|
|||
expect(todo['over'], equals("world"));
|
||||
});
|
||||
|
||||
test("controller in group", () async {
|
||||
var rgx = RegExp("^Hello, world!");
|
||||
var response = await client.get("$url/ctrl_group/todos/0");
|
||||
print('Response: ${response.body}');
|
||||
|
||||
expect(rgx.firstMatch(response.body)?.start, equals(0));
|
||||
|
||||
var todo = json.decode(response.body.replaceAll(rgx, "")) as Map;
|
||||
print("Todo: $todo");
|
||||
expect(todo['text'], equals("Hello"));
|
||||
expect(todo['over'], equals("world"));
|
||||
});
|
||||
|
||||
test("named actions", () async {
|
||||
var response = await client.get("$url/redirect");
|
||||
print('Response: ${response.body}');
|
||||
|
|
Loading…
Reference in a new issue