On the fly route generation with Mojolicious::Lite

Viewed 51

I have the following code

use strict;
use warnings;
use Mojo::UserAgent;
use Mojolicious::Lite;

    get '/test' => sub {
        
        my $host = 'test';
        my ( $c ) = @_;
        
        
    my $ua  = Mojo::UserAgent->new;
    
    
    my $tx = $ua->get($host => {accept => 'application/json'});
    
        
        return $c->render(
            json => $tx->res->json
        );
    };
    app->start;

when run this with Perl myscript.pl daemon and connect let's say https://127.0.0.1:3000/test it will run the code against test

My question how can I make the route dynamic like if i am connecting to https://127.0.0.1:3000/test2 it will run the code against test2 and not test , any idea how to achieve something like this with Mojolicious::Lite.

0 Answers
Related