proxy

Pubbuild status

Angel middleware to forward requests to another server (i.e. webdev serve).Also supports WebSockets.

  1. import 'package:angel_proxy/angel_proxy.dart';
  2. import 'package:http/http.dart' as http;
  3.  
  4. main() async {
  5. // Forward requests instead of serving statically.
  6. // You can also pass a URI, instead of a string.
  7. var proxy1 = Proxy('http://localhost:3000');
  8.  
  9. // handle all methods (GET, POST, ...)
  10. app.fallback(proxy.handleRequest);
  11. }

You can also restrict the proxy to serving only from a specific root:

  1. Proxy(baseUrl, publicPath: '/remote');

Also, you can map requests to a root path on the remote server:

  1. Proxy(baseUrl.replace(path: '/path'));

Request bodies will be forwarded as well, if they are not empty. This allows things like POST requests to function.

For a request body to be forwarded, the body must not have already been parsed.