2021-07-10 04:32:42 +00:00
|
|
|
# Angel3 Proxy
|
|
|
|
|
2022-01-04 12:03:52 +00:00
|
|
|
![Pub Version (including pre-releases)](https://img.shields.io/pub/v/angel3_proxy?include_prereleases)
|
2021-07-10 04:32:42 +00:00
|
|
|
[![version](https://img.shields.io/badge/pub-v4.0.1-brightgreen)](https://pub.dartlang.org/packages/angel3_proxy)
|
2021-06-10 08:47:05 +00:00
|
|
|
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
|
|
|
|
[![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion)
|
2022-01-04 12:03:52 +00:00
|
|
|
[![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/master/packages/proxy/LICENSE)
|
2021-06-10 08:47:05 +00:00
|
|
|
|
2022-01-04 12:03:52 +00:00
|
|
|
Angel3 middleware to forward requests to another server (i.e. `webdev serve`). Also supports WebSockets.
|
2016-11-23 22:03:06 +00:00
|
|
|
|
|
|
|
```dart
|
2021-06-10 08:47:05 +00:00
|
|
|
import 'package:angel3_proxy/angel3_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
|
|
|
|
2021-06-10 08:47:05 +00:00
|
|
|
void main() async {
|
2019-10-12 15:19:57 +00:00
|
|
|
// Forward requests instead of serving statically.
|
|
|
|
// You can also pass a URI, instead of a string.
|
|
|
|
var proxy1 = Proxy('http://localhost:3000');
|
2018-11-02 11:34:45 +00:00
|
|
|
|
|
|
|
// handle all methods (GET, POST, ...)
|
2018-11-09 00:27:50 +00:00
|
|
|
app.fallback(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:
|
2021-07-10 04:32:42 +00:00
|
|
|
|
2017-09-24 18:49:18 +00:00
|
|
|
```dart
|
2019-10-12 15:19:57 +00:00
|
|
|
Proxy(baseUrl, publicPath: '/remote');
|
2017-09-24 18:49:18 +00:00
|
|
|
```
|
|
|
|
|
2018-11-09 00:27:50 +00:00
|
|
|
Also, you can map requests to a root path on the remote server:
|
2021-07-10 04:32:42 +00:00
|
|
|
|
2017-09-24 18:49:18 +00:00
|
|
|
```dart
|
2019-10-12 15:19:57 +00:00
|
|
|
Proxy(baseUrl.replace(path: '/path'));
|
2017-09-24 18:49:18 +00:00
|
|
|
```
|
|
|
|
|
2018-12-09 22:39:11 +00:00
|
|
|
Request bodies will be forwarded as well, if they are not empty. This allows things like POST requests to function.
|
|
|
|
|
2021-07-10 04:32:42 +00:00
|
|
|
For a request body to be forwarded, the body must not have already been parsed.
|