Problem calling Mojolicious::Guides::Tutorial 'group' example

42 views
Skip to first unread message

jk...@verizon.net

unread,
Jun 25, 2016, 4:42:05 PM6/25/16
to Mojolicious
Start by copying code from tutorial to a Perl program:

#####
$ cat group.pl
#!/usr/bin/env perl
use Mojolicious::Lite;

# Global logic shared by all routes
under sub {
  my $c = shift;
  return 1 if $c->req->headers->header('X-Bender');
  $c->render(text => "You're not Bender.");
  return undef;
};

# Admin section
group {

  # Local logic shared only by routes in this group
  under '/admin' => sub {
    my $c = shift;
    return 1 if $c->req->headers->header('X-Awesome');
    $c->render(text => "You're not awesome enough.");
    return undef;
  };

  # GET /admin/dashboard
  get '/dashboard' => {text => 'Nothing to see here yet.'};
};

# GET /welcome
get '/welcome' => {text => 'Hi Bender.'};

app->start;
#####

Start a server:

#####
$ morbo ./group.pl
Server available at http://127.0.0.1:3000
#####

Issue a 'curl' command -- albeit one which may be incorrect:

#####
$ curl -X GET http://localhost:3000 -H "X-Bender: martini" -H "X-Awesome: 1" |head
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
<!DOCTYPE html>    0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
<html>
  <head>
    <title>Page not found (development mode)</title>
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Expires" content="-1">
    <script src="/mojo/jquery/jquery.js"></script>
    <script src="/mojo/prettify/run_prettify.js"></script>
    <link href="/mojo/prettify/prettify-mojo-dark.css" rel="stylesheet">
    <style>
100 16692  100 16692    0     0   848k      0 --:--:-- --:--:-- --:--:--  857k
(23) Failed writing body
#####

And this was the server log output:

#####
[Sat Jun 25 16:22:14 2016] [debug] GET "/"
[Sat Jun 25 16:22:14 2016] [debug] Template "not_found.development.html.ep" not found
[Sat Jun 25 16:22:14 2016] [debug] Template "not_found.html.ep" not found
[Sat Jun 25 16:22:14 2016] [debug] Rendering template "mojo/debug.html.ep"
[Sat Jun 25 16:22:14 2016] [debug] Rendering template "mojo/menubar.html.ep"
[Sat Jun 25 16:22:14 2016] [debug] Your secret passphrase needs to be changed
[Sat Jun 25 16:22:14 2016] [debug] 404 Not Found (0.015911s, 62.850/s)
#####

What am I doing wrong?

Thank you very much.
Jim Keenan


Stefan Adams

unread,
Jun 25, 2016, 5:23:56 PM6/25/16
to mojolicious
On Sat, Jun 25, 2016 at 3:42 PM, <jk...@verizon.net> wrote:
$ curl -X GET http://localhost:3000 -H "X-Bender: martini" -H "X-Awesome: 1" |head
[Sat Jun 25 16:22:14 2016] [debug] GET "/" 

 You issued a GET request for "/", but the only defined routes are "/welcome" and "/admin/dashboard".  You can verify this with

$ perl group.pl routes

Try your curl once again using one of those two routes.

James E Keenan

unread,
Jun 25, 2016, 6:17:47 PM6/25/16
to mojol...@googlegroups.com
Thank you very much; that helped.

$ curl -X GET http://localhost:3000/welcome -H 'X-Bender: martini' -H
'X-Awesome: 1'Hi Bender.

$ curl -X GET http://localhost:3000/admin/dashboard -H 'X-Bender:
martini' -H 'X-Awesome: 1'
Nothing to see here yet.

$ curl -X GET http://localhost:3000/admin/dashboard -H 'X-Bender: martini'

Randall Sindlinger

unread,
Jun 28, 2016, 6:06:07 PM6/28/16
to Mojolicious

On Saturday, June 25, 2016 at 5:23:56 PM UTC-4, Stefan Adams wrote:

$ perl group.pl routes

Try your curl once again using one of those two routes.

I didn't know about this feature - where is it documented that I can find more info on it, and other (useful) arguments to pass to a Mojolicious app like this?

Thanks,
-Randall

Stefan Adams

unread,
Jun 28, 2016, 6:10:30 PM6/28/16
to mojolicious
On Tue, Jun 28, 2016 at 5:06 PM, Randall Sindlinger <rsin...@gmail.com> wrote:
I didn't know about this feature - where is it documented that I can find more info on it,

 
and other (useful) arguments to pass to a Mojolicious app like this?
Reply all
Reply to author
Forward
0 new messages