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