From 487e825f8dcd1b10a9a82fbb6c80016279571f0b Mon Sep 17 00:00:00 2001 From: thosakwe Date: Sun, 23 Jul 2017 23:33:31 -0400 Subject: [PATCH] fix --- lib/src/proxy_layer.dart | 9 ++++++++- lib/src/pub_serve_layer.dart | 2 ++ pubspec.yaml | 2 +- test/basic_test.dart | 3 ++- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/src/proxy_layer.dart b/lib/src/proxy_layer.dart index 02da0210..6034f3cc 100644 --- a/lib/src/proxy_layer.dart +++ b/lib/src/proxy_layer.dart @@ -5,6 +5,9 @@ import 'package:angel_framework/angel_framework.dart'; final RegExp _param = new RegExp(r':([A-Za-z0-9_]+)(\((.+)\))?'); final RegExp _straySlashes = new RegExp(r'(^/+)|(/+$)'); +/// Used to mount a route for a [ProxyLayer]. +typedef Route ProxyLayerRouteAssigner(Router router, String path, handler); + String _pathify(String path) { var p = path.replaceAll(_straySlashes, ''); @@ -53,6 +56,7 @@ class ProxyLayer { final int port; final String protocol; final Duration timeout; + ProxyLayerRouteAssigner routeAssigner; ProxyLayer( this.host, @@ -65,10 +69,13 @@ class ProxyLayer { this.recoverFrom404: true, this.streamToIO: false, this.timeout, + this.routeAssigner, SecurityContext securityContext, }) { _client = new HttpClient(context: securityContext); _prefix = publicPath.replaceAll(_straySlashes, ''); + routeAssigner ??= + (Router router, String path, handler) => router.get(path, handler); } call(Angel app) async => serve(this.app = app); @@ -83,7 +90,7 @@ class ProxyLayer { return serveFile(path, req, res); } - router.all('$publicPath/*', handler); + routeAssigner(router, '$publicPath/*', handler); } serveFile(String path, RequestContext req, ResponseContext res) async { diff --git a/lib/src/pub_serve_layer.dart b/lib/src/pub_serve_layer.dart index 3ea53d71..59c59615 100644 --- a/lib/src/pub_serve_layer.dart +++ b/lib/src/pub_serve_layer.dart @@ -12,6 +12,7 @@ class PubServeLayer extends ProxyLayer { int port: 8080, String protocol: 'http', String publicPath: '/', + ProxyLayerRouteAssigner routeAssigner, Duration timeout}) : super(host, port, debug: debug, @@ -21,6 +22,7 @@ class PubServeLayer extends ProxyLayer { recoverFromDead: recoverFromDead != false, recoverFrom404: recoverFrom404 != false, streamToIO: streamToIO != false, + routeAssigner: routeAssigner, timeout: timeout); @override diff --git a/pubspec.yaml b/pubspec.yaml index 47b04e9a..4f1a5383 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: angel_proxy description: Angel middleware to forward requests to another server (i.e. pub serve). -version: 1.0.8 +version: 1.0.9 author: Tobe O homepage: https://github.com/angel-dart/proxy environment: diff --git a/test/basic_test.dart b/test/basic_test.dart index 8e1f02d0..d47eca3f 100644 --- a/test/basic_test.dart +++ b/test/basic_test.dart @@ -20,7 +20,8 @@ main() { await app.configure(new ProxyLayer( testServer.address.address, testServer.port, - publicPath: '/proxy')); + publicPath: '/proxy', + routeAssigner: (router, path, handler) => router.all(path, handler))); await app.configure(new ProxyLayer( testServer.address.address, testServer.port, mapTo: '/foo'));