From 39d70e74a6650178bf344e6762bb3673974fa178 Mon Sep 17 00:00:00 2001 From: thosakwe Date: Thu, 24 Nov 2016 02:12:53 -0500 Subject: [PATCH] All fall through --- README.md | 2 +- lib/src/http/server.dart | 13 ++++++------- lib/src/http/server_shelved.dart | 19 +++++++++++++++++++ lib/src/util.dart | 2 -- pubspec.yaml | 3 ++- test/controller_test.dart | 13 +++++-------- 6 files changed, 33 insertions(+), 19 deletions(-) create mode 100644 lib/src/http/server_shelved.dart diff --git a/README.md b/README.md index e041d96e..54d218a8 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # angel_framework -![version 1.0.0-dev.24](https://img.shields.io/badge/version-1.0.0--dev.24-red.svg) +![version 1.0.0-dev.25](https://img.shields.io/badge/version-1.0.0--dev.25-red.svg) ![build status](https://travis-ci.org/angel-dart/framework.svg) Core libraries for the Angel Framework. \ No newline at end of file diff --git a/lib/src/http/server.dart b/lib/src/http/server.dart index 38a258f0..6d1bc003 100644 --- a/lib/src/http/server.dart +++ b/lib/src/http/server.dart @@ -5,6 +5,7 @@ import 'dart:io'; import 'dart:math' show Random; import 'dart:mirrors'; import 'package:json_god/json_god.dart' as god; +import 'package:shelf/shelf.dart' as shelf; import 'angel_base.dart'; import 'angel_http_exception.dart'; import 'controller.dart'; @@ -13,6 +14,7 @@ import 'response_context.dart'; import 'routable.dart'; import 'service.dart'; export 'package:container/container.dart'; +part 'server_shelved.dart'; final RegExp _straySlashes = new RegExp(r'(^/+)|(/+$)'); @@ -33,8 +35,8 @@ class Angel extends AngelBase { var _fatalErrorStream = new StreamController.broadcast(); var _onController = new StreamController.broadcast(); final Random _rand = new Random.secure(); - ServerGenerator _serverGenerator = - (address, port) async => await HttpServer.bind(address, port); + + ServerGenerator _serverGenerator = HttpServer.bind; /// Fired after a request is processed. Always runs. Stream get afterProcessed => _afterProcessed.stream; @@ -183,12 +185,9 @@ class Angel extends AngelBase { if (requestedUrl.isEmpty) requestedUrl = '/'; - final resolved = []; + final resolved = resolveAll(requestedUrl, method: request.method); - if (requestedUrl == '/') { - resolved.add(root.indexRoute); - } else { - resolved.addAll(resolveAll(requestedUrl, method: request.method)); + if (resolved.isNotEmpty) { final route = resolved.first; req.params.addAll(route?.parseParameters(requestedUrl) ?? {}); req.inject(Match, route.match(requestedUrl)); diff --git a/lib/src/http/server_shelved.dart b/lib/src/http/server_shelved.dart new file mode 100644 index 00000000..0f7c77a3 --- /dev/null +++ b/lib/src/http/server_shelved.dart @@ -0,0 +1,19 @@ +part of angel_framework.http.server; + + +// Todo: Shelf interop +class ShelvedAngel extends Angel { + shelf.Pipeline pipeline = new shelf.Pipeline(); + + ShelvedAngel({bool debug: false}) : super(debug: debug) {} + + @override + Future startServer([InternetAddress address, int port]) async { + /* final handler = pipeline.addHandler((shelf.Request req) { + // io.handleRequest() + });*/ + + return await super.startServer(address, port); + } + +} diff --git a/lib/src/util.dart b/lib/src/util.dart index ad614889..710391b8 100644 --- a/lib/src/util.dart +++ b/lib/src/util.dart @@ -21,6 +21,4 @@ getAnnotation(obj, Type T) { ClassMirror classMirror = reflectClass(obj.runtimeType); return matchingAnnotation(classMirror.metadata, T); } - - return null; } \ No newline at end of file diff --git a/pubspec.yaml b/pubspec.yaml index e22d5e84..38676067 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: angel_framework -version: 1.0.0-dev.24 +version: 1.0.0-dev.25 description: Core libraries for the Angel framework. author: Tobe O homepage: https://github.com/angel-dart/angel_framework @@ -12,6 +12,7 @@ dependencies: json_god: ^2.0.0-beta merge_map: ^1.0.0 mime: ^0.9.3 + shelf: ^0.6.7 dev_dependencies: http: ^0.11.3 test: ^0.12.13 diff --git a/test/controller_test.dart b/test/controller_test.dart index 2fb6e7bc..4490b3ea 100644 --- a/test/controller_test.dart +++ b/test/controller_test.dart @@ -28,10 +28,8 @@ class TodoController extends Controller { main() { Angel app; HttpServer server; - InternetAddress host = InternetAddress.LOOPBACK_IP_V4; - int port = 3000; - http.Client client; - String url = "http://${host.address}:$port"; + http.Client client = new http.Client(); + String url; setUp(() async { app = new Angel(); @@ -46,15 +44,14 @@ main() { print(app.controllers); app.dumpTree(); - server = await app.startServer(host, port); - client = new http.Client(); + server = await app.startServer(); + url = 'http://${server.address.address}:${server.port}'; }); tearDown(() async { await server.close(force: true); app = null; - client.close(); - client = null; + url = null; }); test("middleware", () async {