fix
This commit is contained in:
parent
e05d35ee67
commit
487e825f8d
4 changed files with 13 additions and 3 deletions
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 <thosakwe@gmail.com>
|
||||
homepage: https://github.com/angel-dart/proxy
|
||||
environment:
|
||||
|
|
|
@ -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'));
|
||||
|
|
Loading…
Reference in a new issue