Updated README

This commit is contained in:
denkuy 2018-11-02 12:34:45 +01:00
parent fc1b1e5666
commit 2d7ae5a547

View file

@ -2,7 +2,7 @@
[![Pub](https://img.shields.io/pub/v/angel_proxy.svg)](https://pub.dartlang.org/packages/angel_proxy)
[![build status](https://travis-ci.org/angel-dart/proxy.svg)](https://travis-ci.org/angel-dart/proxy)
Angel middleware to forward requests to another server (i.e. `pub serve`).
Angel middleware to forward requests to another server (i.e. `webdev serve`).
```dart
import 'package:angel_proxy/angel_proxy.dart';
@ -11,23 +11,26 @@ import 'package:http/http.dart' as http;
main() async {
// ...
var client = new http.Client();
var proxy = new Proxy(app, client, 'http://localhost:3000');
var client = http.Client();
// Forward requests instead of serving statically
app.use(proxy.handleRequest);
var proxy1 = Proxy(client, 'http://localhost:3000');
// or split: Proxy(client, 'localhost', port: 8080, protocol: 'http');
// handle all methods (GET, POST, ...)
app.all('*', proxy.handleRequest);
}
```
You can also restrict the proxy to serving only from a specific root:
```dart
new Proxy(app, client, '<host>', publicPath: '/remote');
Proxy(client, '<host>', publicPath: '/remote');
```
Also, you can map requests to a root path on the remote server
```dart
new Proxy(app, client, '<host>', mapTo: '/path');
Proxy(client, '<host>', mapTo: '/path');
```
If your app's `storeOriginalBuffer` is `true`, then request bodies will be forwarded
If your app's `keepRawRequestBuffers` is `true`, then request bodies will be forwarded
as well, if they are not empty. This allows things like POST requests to function.