42
This commit is contained in:
parent
c771e82ad3
commit
f00705d2d0
5 changed files with 78 additions and 55 deletions
|
@ -2,11 +2,7 @@
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="7b89ff1e-1260-4dcf-9c3d-345de0471ea1" name="Default" comment="">
|
<list default="true" id="7b89ff1e-1260-4dcf-9c3d-345de0471ea1" name="Default" comment="">
|
||||||
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/runConfigurations/DI_Tests.xml" afterPath="$PROJECT_DIR$/.idea/runConfigurations/DI_Tests.xml" />
|
|
||||||
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
|
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
|
||||||
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/lib/src/http/angel_http_exception.dart" afterPath="$PROJECT_DIR$/lib/src/http/angel_http_exception.dart" />
|
|
||||||
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/lib/src/http/controller.dart" afterPath="$PROJECT_DIR$/lib/src/http/controller.dart" />
|
|
||||||
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/lib/src/http/memory_service.dart" afterPath="$PROJECT_DIR$/lib/src/http/memory_service.dart" />
|
|
||||||
</list>
|
</list>
|
||||||
<ignored path="$PROJECT_DIR$/.tmp/" />
|
<ignored path="$PROJECT_DIR$/.tmp/" />
|
||||||
<ignored path="$PROJECT_DIR$/temp/" />
|
<ignored path="$PROJECT_DIR$/temp/" />
|
||||||
|
@ -62,8 +58,8 @@
|
||||||
<file leaf-file-name="server.dart" pinned="false" current-in-tab="true">
|
<file leaf-file-name="server.dart" pinned="false" current-in-tab="true">
|
||||||
<entry file="file://$PROJECT_DIR$/lib/src/http/server.dart">
|
<entry file="file://$PROJECT_DIR$/lib/src/http/server.dart">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state relative-caret-position="175">
|
<state relative-caret-position="205">
|
||||||
<caret line="237" column="42" lean-forward="true" selection-start-line="237" selection-start-column="42" selection-end-line="237" selection-end-column="42" />
|
<caret line="239" column="43" lean-forward="false" selection-start-line="239" selection-start-column="43" selection-end-line="239" selection-end-column="43" />
|
||||||
<folding>
|
<folding>
|
||||||
<element signature="e#38#58#0" expanded="true" />
|
<element signature="e#38#58#0" expanded="true" />
|
||||||
<marker date="1483149636000" expanded="true" signature="14571:14573" ph="{...}" />
|
<marker date="1483149636000" expanded="true" signature="14571:14573" ph="{...}" />
|
||||||
|
@ -384,7 +380,7 @@
|
||||||
<workItem from="1481377809918" duration="1319000" />
|
<workItem from="1481377809918" duration="1319000" />
|
||||||
<workItem from="1481389675241" duration="158000" />
|
<workItem from="1481389675241" duration="158000" />
|
||||||
<workItem from="1481390924053" duration="19000" />
|
<workItem from="1481390924053" duration="19000" />
|
||||||
<workItem from="1483149948840" duration="913000" />
|
<workItem from="1483149948840" duration="930000" />
|
||||||
</task>
|
</task>
|
||||||
<task id="LOCAL-00001" summary="Re-designed exception">
|
<task id="LOCAL-00001" summary="Re-designed exception">
|
||||||
<created>1481237183504</created>
|
<created>1481237183504</created>
|
||||||
|
@ -421,7 +417,14 @@
|
||||||
<option name="project" value="LOCAL" />
|
<option name="project" value="LOCAL" />
|
||||||
<updated>1483150316138</updated>
|
<updated>1483150316138</updated>
|
||||||
</task>
|
</task>
|
||||||
<option name="localTasksCounter" value="6" />
|
<task id="LOCAL-00006" summary="I love stack overflows!!!">
|
||||||
|
<created>1483150975010</created>
|
||||||
|
<option name="number" value="00006" />
|
||||||
|
<option name="presentableId" value="LOCAL-00006" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1483150975010</updated>
|
||||||
|
</task>
|
||||||
|
<option name="localTasksCounter" value="7" />
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="TestHistory">
|
<component name="TestHistory">
|
||||||
|
@ -457,7 +460,7 @@
|
||||||
</history-entry>
|
</history-entry>
|
||||||
</component>
|
</component>
|
||||||
<component name="TimeTrackingManager">
|
<component name="TimeTrackingManager">
|
||||||
<option name="totallyTimeSpent" value="3597000" />
|
<option name="totallyTimeSpent" value="3614000" />
|
||||||
</component>
|
</component>
|
||||||
<component name="TodoView">
|
<component name="TodoView">
|
||||||
<todo-panel id="selected-file">
|
<todo-panel id="selected-file">
|
||||||
|
@ -479,7 +482,7 @@
|
||||||
<window_info id="Dart Analysis" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32802936" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
|
<window_info id="Dart Analysis" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32802936" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
|
||||||
<window_info id="ANTLR Preview" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
|
<window_info id="ANTLR Preview" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
|
||||||
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
|
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
|
||||||
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.32925338" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
|
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32925338" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
|
||||||
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
|
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
|
||||||
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32680538" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
|
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32680538" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
|
||||||
<window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="true" content_ui="tabs" />
|
<window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="true" content_ui="tabs" />
|
||||||
|
@ -506,7 +509,8 @@
|
||||||
<MESSAGE value="Fixed todo" />
|
<MESSAGE value="Fixed todo" />
|
||||||
<MESSAGE value="Done???" />
|
<MESSAGE value="Done???" />
|
||||||
<MESSAGE value="findExpose" />
|
<MESSAGE value="findExpose" />
|
||||||
<option name="LAST_COMMIT_MESSAGE" value="findExpose" />
|
<MESSAGE value="I love stack overflows!!!" />
|
||||||
|
<option name="LAST_COMMIT_MESSAGE" value="I love stack overflows!!!" />
|
||||||
</component>
|
</component>
|
||||||
<component name="XDebuggerManager">
|
<component name="XDebuggerManager">
|
||||||
<breakpoint-manager />
|
<breakpoint-manager />
|
||||||
|
@ -881,8 +885,8 @@
|
||||||
</entry>
|
</entry>
|
||||||
<entry file="file://$PROJECT_DIR$/lib/src/http/server.dart">
|
<entry file="file://$PROJECT_DIR$/lib/src/http/server.dart">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state relative-caret-position="175">
|
<state relative-caret-position="205">
|
||||||
<caret line="237" column="42" lean-forward="true" selection-start-line="237" selection-start-column="42" selection-end-line="237" selection-end-column="42" />
|
<caret line="239" column="43" lean-forward="false" selection-start-line="239" selection-start-column="43" selection-end-line="239" selection-end-column="43" />
|
||||||
<folding>
|
<folding>
|
||||||
<element signature="e#38#58#0" expanded="true" />
|
<element signature="e#38#58#0" expanded="true" />
|
||||||
<marker date="1483149636000" expanded="true" signature="14571:14573" ph="{...}" />
|
<marker date="1483149636000" expanded="true" signature="14571:14573" ph="{...}" />
|
||||||
|
|
18
README.md
18
README.md
|
@ -1,6 +1,22 @@
|
||||||
# angel_framework
|
# angel_framework
|
||||||
|
|
||||||
[![pub 1.0.0-dev.40](https://img.shields.io/badge/pub-1.0.0--dev.40-red.svg)](https://pub.dartlang.org/packages/angel_framework)
|
[![pub 1.0.0-dev.42](https://img.shields.io/badge/pub-1.0.0--dev.42-red.svg)](https://pub.dartlang.org/packages/angel_framework)
|
||||||
[![build status](https://travis-ci.org/angel-dart/framework.svg)](https://travis-ci.org/angel-dart/framework)
|
[![build status](https://travis-ci.org/angel-dart/framework.svg)](https://travis-ci.org/angel-dart/framework)
|
||||||
|
|
||||||
Core libraries for the Angel Framework.
|
Core libraries for the Angel Framework.
|
||||||
|
|
||||||
|
```dart
|
||||||
|
import 'package:angel_framework/angel_framework.dart';
|
||||||
|
|
||||||
|
main() async {
|
||||||
|
var app = new Angel();
|
||||||
|
|
||||||
|
app
|
||||||
|
..get('/hello', (req, res) {
|
||||||
|
res.write('world!');
|
||||||
|
})
|
||||||
|
..post('/date', () => new DateTime.now().toString());
|
||||||
|
|
||||||
|
await app.startServer();
|
||||||
|
}
|
||||||
|
```
|
|
@ -45,7 +45,6 @@ class Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
var routable = new Routable(debug: debug);
|
var routable = new Routable(debug: debug);
|
||||||
|
|
||||||
app.use(exposeDecl.path, routable);
|
app.use(exposeDecl.path, routable);
|
||||||
TypeMirror typeMirror = reflectType(this.runtimeType);
|
TypeMirror typeMirror = reflectType(this.runtimeType);
|
||||||
String name = exposeDecl.as?.isNotEmpty == true
|
String name = exposeDecl.as?.isNotEmpty == true
|
||||||
|
@ -79,21 +78,23 @@ class Controller {
|
||||||
|
|
||||||
var reflectedMethod = instanceMirror.getField(methodName).reflectee;
|
var reflectedMethod = instanceMirror.getField(methodName).reflectee;
|
||||||
var middleware = []..addAll(handlers)..addAll(exposeDecl.middleware);
|
var middleware = []..addAll(handlers)..addAll(exposeDecl.middleware);
|
||||||
|
String name = exposeDecl.as?.isNotEmpty == true
|
||||||
|
? exposeDecl.as
|
||||||
|
: MirrorSystem.getName(methodName);
|
||||||
|
|
||||||
// Check if normal
|
// Check if normal
|
||||||
if (method.parameters.length == 2 &&
|
if (method.parameters.length == 2 &&
|
||||||
method.parameters[0].type.reflectedType == RequestContext &&
|
method.parameters[0].type.reflectedType == RequestContext &&
|
||||||
method.parameters[1].type.reflectedType == ResponseContext) {
|
method.parameters[1].type.reflectedType == ResponseContext) {
|
||||||
// Create a regular route
|
// Create a regular route
|
||||||
routable.addRoute(exposeDecl.method, exposeDecl.path, reflectedMethod,
|
routeMappings[name] = routable
|
||||||
middleware: middleware);
|
.addRoute(exposeDecl.method, exposeDecl.path, (req, res) async {
|
||||||
|
var result = await reflectedMethod(req, res);
|
||||||
|
return result is RequestHandler ? await result(req, res) : result;
|
||||||
|
}, middleware: middleware);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String name = exposeDecl.as?.isNotEmpty == true
|
|
||||||
? exposeDecl.as
|
|
||||||
: MirrorSystem.getName(methodName);
|
|
||||||
|
|
||||||
routeMappings[name] = routable.addRoute(
|
routeMappings[name] = routable.addRoute(
|
||||||
exposeDecl.method,
|
exposeDecl.method,
|
||||||
exposeDecl.path,
|
exposeDecl.path,
|
||||||
|
@ -119,40 +120,43 @@ RequestHandler handleContained(handler, InjectionRequest injection) {
|
||||||
List args = [];
|
List args = [];
|
||||||
|
|
||||||
void inject(requirement) {
|
void inject(requirement) {
|
||||||
for (var requirement in injection.required) {
|
|
||||||
if (requirement == RequestContext) {
|
if (requirement == RequestContext) {
|
||||||
args.add(req);
|
args.add(req);
|
||||||
} else if (requirement == ResponseContext) {
|
} else if (requirement == ResponseContext) {
|
||||||
args.add(res);
|
args.add(res);
|
||||||
} else if (requirement is String) {
|
} else if (requirement is String) {
|
||||||
if (req.params.containsKey(requirement)) {} else if (req.injections
|
if (req.params.containsKey(requirement)) {
|
||||||
.containsKey(requirement))
|
args.add(req.params[requirement]);
|
||||||
|
} else if (req.injections.containsKey(requirement))
|
||||||
args.add(req.injections[requirement]);
|
args.add(req.injections[requirement]);
|
||||||
else {
|
else {
|
||||||
throw new ArgumentError(
|
throw new ArgumentError(
|
||||||
"Cannot resolve parameter '$requirement' within handler.");
|
"Cannot resolve parameter '$requirement' within handler.");
|
||||||
}
|
}
|
||||||
args.add(req.params[requirement]);
|
} else if (requirement is List &&
|
||||||
} else if (requirement is List) {
|
requirement.length == 2 &&
|
||||||
for (var child in requirement) {
|
requirement.first is String &&
|
||||||
try {
|
requirement.last is Type) {
|
||||||
inject(child);
|
String key = requirement.first;
|
||||||
break;
|
Type type = requirement.last;
|
||||||
} catch (e) {
|
|
||||||
rethrow;
|
if (req.params.containsKey(key) || req.injections.containsKey(key)) {
|
||||||
}
|
inject(key);
|
||||||
}
|
} else
|
||||||
|
inject(type);
|
||||||
} else if (requirement is Type && requirement != dynamic) {
|
} else if (requirement is Type && requirement != dynamic) {
|
||||||
args.add(
|
if (req.injections.containsKey(requirement))
|
||||||
req.app.container.make(requirement, injecting: req.injections));
|
args.add(req.injections[requirement]);
|
||||||
|
else
|
||||||
|
args.add(req.app.container.make(requirement));
|
||||||
} else {
|
} else {
|
||||||
throw new ArgumentError(
|
throw new ArgumentError(
|
||||||
'$requirement cannot be injected into a request handler.');
|
'$requirement cannot be injected into a request handler.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
injection.required.forEach(inject);
|
injection.required.forEach(inject);
|
||||||
return Function.apply(handler, args);
|
var result = Function.apply(handler, args);
|
||||||
|
return result is Future ? await result : result;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -321,10 +321,9 @@ class Angel extends AngelBase {
|
||||||
/// Runs with DI, and *always* reflects. Prefer [runContained].
|
/// Runs with DI, and *always* reflects. Prefer [runContained].
|
||||||
Future runReflected(
|
Future runReflected(
|
||||||
Function handler, RequestContext req, ResponseContext res) async {
|
Function handler, RequestContext req, ResponseContext res) async {
|
||||||
var injection = preInjection(handler);
|
var h =
|
||||||
|
handleContained(handler, _preContained[handler] = preInject(handler));
|
||||||
_preContained[handler] = injection;
|
return await h(req, res);
|
||||||
return handleContained(handler, injection);
|
|
||||||
// return await closureMirror.apply(args).reflectee;
|
// return await closureMirror.apply(args).reflectee;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
name: angel_framework
|
name: angel_framework
|
||||||
version: 1.0.0-dev.41
|
version: 1.0.0-dev.42
|
||||||
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