platform/README.md

37 lines
1.1 KiB
Markdown
Raw Normal View History

2017-09-24 18:49:18 +00:00
# proxy
[![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)
2016-11-23 22:03:06 +00:00
2018-11-02 11:34:45 +00:00
Angel middleware to forward requests to another server (i.e. `webdev serve`).
2016-11-23 22:03:06 +00:00
```dart
import 'package:angel_proxy/angel_proxy.dart';
2017-09-24 18:49:18 +00:00
import 'package:http/http.dart' as http;
2016-11-23 22:03:06 +00:00
main() async {
// ...
2018-11-02 11:34:45 +00:00
var client = http.Client();
2016-11-23 22:03:06 +00:00
2017-09-24 18:49:18 +00:00
// Forward requests instead of serving statically
2018-11-02 11:34:45 +00:00
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);
2016-11-23 22:03:06 +00:00
}
2017-04-02 02:06:27 +00:00
```
2017-09-24 18:49:18 +00:00
You can also restrict the proxy to serving only from a specific root:
```dart
2018-11-02 11:34:45 +00:00
Proxy(client, '<host>', publicPath: '/remote');
2017-09-24 18:49:18 +00:00
```
Also, you can map requests to a root path on the remote server
```dart
2018-11-02 11:34:45 +00:00
Proxy(client, '<host>', mapTo: '/path');
2017-09-24 18:49:18 +00:00
```
2018-11-02 11:34:45 +00:00
If your app's `keepRawRequestBuffers` is `true`, then request bodies will be forwarded
2017-04-10 02:15:45 +00:00
as well, if they are not empty. This allows things like POST requests to function.