GithubHelp home page GithubHelp logo

mohawk2 / mojolicious-command-proxy Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 20 KB

Add routes to an app that proxy to another app

Home Page: https://metacpan.org/pod/Mojolicious::Command::proxy

Perl 100.00%

mojolicious-command-proxy's Introduction

NAME

Mojolicious::Command::proxy - Proxy web requests elsewhere

PROJECT STATUS

OS Build status
Linux Build Status

CPAN version

SYNOPSIS

Usage: APPLICATION proxy [--from route_prefix] to_url

  mojo proxy http://example.com/subdir daemon -l http://*:3000
  mojo proxy -f /proxy http://example.com/subdir get /proxy/hi

Options:
  -f, --from                  Proxying route prefix

DESCRIPTION

Mojolicious::Command::proxy is a command line interface for making an app that proxies some or all incoming requests elsewhere. Having done so, it then passes the rest of its arguments to the app's start method, as illustrated in the synopsis above.

One major reason for this is to be able to point your browser at e.g. localhost:3000 (see first example in synopsis). This relaxes restrictions on e.g. Service Workers and push notifications, which normally demand TLS, so you can test functionality even if your real development server is running elsewhere.

ATTRIBUTES

description

$str = $self->description;

usage

$str = $self->usage;

METHODS

run

$get->run(@ARGV);

Run this command. It will add a "proxy" route as below. If not supplied, the $from will be empty-string.

Command-line arguments will only be parsed at the start of the command-line. This allows you to pass option through to e.g. daemon.

As a special case, if the app attribute is exactly a Mojo::HelloWorld app, it will replace its routes attribute with an empty one first, since the whatever route clashes with the proxy route, being also a match-everything wildcard route. This makes the mojo proxy invocation function as expected.

proxy

Mojolicious::Command::proxy->proxy($app, $from_prefix, $to_prefix);

Add a route to the given app, with the given prefix, named proxy. It will transparently proxy all matching requests to the give $to, with all the same headers both ways.

It operates by simply appending everything after the $from_prefix, which can be an empty string (which is treated the same as solitary /, doing what you'd expect), to the $to_prefix. E.g.:

$cmd->proxy($app, '', '/subdir'); # /2 -> /subdir/2, / -> /subdir/ i.e. all
$cmd->proxy($app, '/proxy', '/subdir'); # /proxy/2 -> /subdir/2

$to can be a path as well as a full URL, so you can also use this to route internally. However, the author can see no good reason to do this outside of testing.

It uses "proxy->start_p" in Mojolicious::Plugin::DefaultHelpers but adds the full header-proxying behaviour.

AUTHOR

Ed J

COPYRIGHT AND LICENSE

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

mojolicious-command-proxy's People

Contributors

mohawk2 avatar

Watchers

 avatar  avatar

mojolicious-command-proxy's Issues

Route pattern "/proxy*path" contains a reserved stash value

Test suite fails with Mojolicious 9.x:

Route pattern "/proxy*path" contains a reserved stash value at /usr/home/cpansand/.cpan/build/2021030716/Mojolicious-Command-proxy-0.004-2/blib/lib/Mojolicious/Command/proxy.pm line 43.
t/command-local.t ...... 
Dubious, test returned 255 (wstat 65280, 0xff00)
No subtests run 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.