Last active
August 6, 2023 17:09
-
-
Save ology/5078e3e973cc18e1d0a187ba104333d7 to your computer and use it in GitHub Desktop.
Mojo route does not fire?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub startup ($self) { | |
$self->plugin('RemoteAddr'); | |
$self->plugin('browser_detect'); | |
$self->plugin('Thumbnail'); | |
$self->plugin('AuthEg::Plugin'); | |
$self->plugin('AuthEg::DB::Plugin'); | |
my $config = $self->plugin('NotYAMLConfig'); | |
$self->secrets($config->{secrets}); | |
my $r = $self->routes; | |
$r->get('/') ->to('Main#index') ->name('index'); | |
$r->post('/login')->to('Main#login') ->name('login'); | |
$r->get('/logout')->to('Main#logout')->name('logout'); | |
$r->get('/album/#img')->to('main#image')->name('show_image'); | |
my $authed = $r->under('/authed')->to('Main#authorize'); | |
for my $endpoint (qw(accounts addresses album calendar chat profile recipes password username log genealogy)) { | |
$authed->get("/$endpoint")->to("Main#$endpoint")->name($endpoint); | |
} | |
$authed->post('/chat') ->to('Main#chat_post') ->name('chat_post'); | |
$authed->post('/calendar') ->to('Main#calendar_post') ->name('calendar_post'); | |
$authed->post('/addresses') ->to('Main#address_post') ->name('address_post'); | |
$authed->post('/password') ->to('Main#password_post') ->name('password_post'); | |
$authed->post('/username') ->to('Main#username_post') ->name('username_post'); | |
$authed->post('/album') ->to('Main#album_post') ->name('album_post'); | |
$authed->post('/genealogy') ->to('Main#genealogy_post')->name('genealogy_post'); | |
$authed->get('/delete_event') ->to('Main#delete_event') ->name('delete_event'); | |
$authed->get('/delete_place') ->to('Main#delete_place') ->name('delete_place'); | |
$authed->get('/delete_image') ->to('Main#delete_image') ->name('delete_image'); | |
$authed->get('/delete_person')->to('Main#delete_person') ->name('delete_person'); | |
$authed->post('/add') ->to('Main#new_user') ->name('add'); | |
$authed->get('/remove') ->to('Main#delete_user') ->name('remove'); | |
$authed->get('/tag') ->to('Main#tag_chat') ->name('tag'); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub image ($self) { | |
warn __PACKAGE__,' L',__LINE__,' ',,"HELLO??\n"; | |
unless ($self->session->{user}) { | |
return $self->render(text => 'Forbidden', status => 403); | |
} | |
my $file_name = $self->param('img'); | |
my $file = Mojo::File->new(ALBUM_PATH . $file_name); | |
unless ($file) { | |
return $self->render(text => 'Not found', status => 404); | |
} | |
$self->render(data => $file->slurp); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
▸ perl script/auth_eg routes -v | |
/ .... GET "index" ^ | |
/login .... POST "login" ^\/login | |
/logout .... GET "logout" ^\/logout | |
/album/#img .... GET "show_image" ^\/album/([^/]+) | |
/authed ..U. * authed ^\/authed | |
+/accounts .... GET "accounts" ^\/accounts | |
+/addresses .... GET "addresses" ^\/addresses | |
+/album .... GET "album" ^\/album | |
+/calendar .... GET "calendar" ^\/calendar | |
+/chat .... GET "chat" ^\/chat | |
+/profile .... GET "profile" ^\/profile | |
+/recipes .... GET "recipes" ^\/recipes | |
+/password .... GET "password" ^\/password | |
+/username .... GET "username" ^\/username | |
+/log .... GET "log" ^\/log | |
+/genealogy .... GET "genealogy" ^\/genealogy | |
+/chat .... POST "chat_post" ^\/chat | |
+/calendar .... POST "calendar_post" ^\/calendar | |
+/addresses .... POST "address_post" ^\/addresses | |
+/password .... POST "password_post" ^\/password | |
+/username .... POST "username_post" ^\/username | |
+/album .... POST "album_post" ^\/album | |
+/genealogy .... POST "genealogy_post" ^\/genealogy | |
+/delete_event .... GET "delete_event" ^\/delete_event | |
+/delete_place .... GET "delete_place" ^\/delete_place | |
+/delete_image .... GET "delete_image" ^\/delete_image | |
+/delete_person .... GET "delete_person" ^\/delete_person | |
+/add .... POST "add" ^\/add | |
+/remove .... GET "remove" ^\/remove | |
+/tag .... GET "tag" ^\/tag |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment