jaguar_dev_proxy 2.4.4

  • Readme
  • Changelog
  • Installing
  • 25

jaguar_dev_proxy #

Provides PrefixedProxyServer to reverse proxy certain selected requests to another server.

This is similar to Nginx's reverse proxy.

Usage #

An instance of PrefixedProxyServer has to be created and added to a Jaguar server. The constructor of PrefixedProxyServer takes all the necessary parameters to configure the reverse proxy.

The job of the reverse proxy is to

  1. Match certain paths
  2. Transform it to a target path
  3. Forward the received request to the target path
  4. Forward the response obtained from server to the client

Step 1 and 2 requires configuration.

The matched path #

The first parameter (path) to the constructor is used to match the incoming URL/route. The matching is based on prefix. For example:

When path is /html, it will match:

  • /html
  • /html/
  • /html/index.html
  • /html/static/index.html

Target path #

The second parameter (proxyBaseUrl) is used to transform the incoming request URL to reverse proxy target URL. The proxyBaseUrl is just prefixed to the remaining part after path is matched match. For example:

For new PrefixedProxyServer('/html', 'http://localhost:8000/client'),

  • /html is mapped into http://localhost:8000/client/
  • /html/ is mapped into http://localhost:8000/client/
  • /html/index.html is mapped into http://localhost:8000/client/index.html
  • /html/static/index.html is mapped into http://localhost:8000/client/static/index.html

Boilerplate #

The boilerplate example to showcasing reverse proxy capabilities of Jaguar can be found at Reverse proxy example.

Simple example #

A simple usage example:

import 'package:jaguar/jaguar.dart';
import 'package:jaguar_dev_proxy/jaguar_dev_proxy.dart';

main() async {
  // Proxy all html client requests to pub server
  // NOTE: Run pub server on port 8000 using command
  //     pub run build_runner serve web:8000
  final proxy = PrefixedProxyServer('/client', 'http://localhost:8000/');

  final server = Jaguar(address: 'localhost', port: 8085);
  server.getJson('/api/user', (Context ctx) => {'name': 'teja'});
  await server.serve(logRequests: true);

Changelog #

33 2.1.4

  • Dart 2 stable

2.1.2 #

  • before and after interceptors

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  jaguar_dev_proxy: ^2.4.4

2. Install it

You can install packages from the command line:

with pub:

$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:jaguar_dev_proxy/jaguar_dev_proxy.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jul 2, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.9+1

Health issues and suggestions

Fix lib/jaguar_dev_proxy.dart. (-44.87 points)

Analysis of lib/jaguar_dev_proxy.dart failed with 2 errors, 4 hints, including:

line 58 col 14: The function 'Builtin404ErrorResponse' isn't defined.

line 76 col 14: The function 'Builtin404ErrorResponse' isn't defined.

line 43 col 21: Use = to separate a named parameter from its default value.

line 44 col 21: Use = to separate a named parameter from its default value.

line 76 col 7: DO use curly braces for all flow control structures.

Maintenance issues and suggestions

No valid SDK. (-20 points)

The analysis could not detect a valid SDK that can use this package.

Package is getting outdated. (-50.96 points)

The package was last published 78 weeks ago.

The package description is too short. (-17 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Maintain an example.

None of the files in the package's example/ directory matches known example patterns.

Common filename patterns include main.dart, example.dart, and jaguar_dev_proxy.dart. Packages with multiple examples should provide example/

For more information see the pub package layout conventions.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.65 <3.0.0
jaguar ^2.4.14 2.4.43
path ^1.6.2 1.7.0
Transitive dependencies
auth_header 2.1.4
charcode 1.1.3
collection 1.14.13
convert 2.1.1
crypto 2.1.5
http_server 0.9.8+3
jaguar_common 2.1.4
jaguar_serializer 2.2.12
logging 0.11.4
meta 1.1.8 1.2.0
mime 0.9.6+3
path_tree 2.2.2
stack_trace 1.9.5
typed_data 1.2.0
Dev dependencies
build_runner ^0.10.0
build_web_compilers ^0.4.1
test ^1.3.0