Action is not allowed Template not found

19 views
Skip to first unread message

VadimN

unread,
Sep 13, 2019, 1:39:28 AM9/13/19
to Mojolicious
Hi,

Using Websocket technology to periodically send new rows to the page.

Under lite version all works fine.

Server log for getting page, establishing WS connection, sending occasional new row to the page:

at http://127.0.0.1:3000
:44.91645] [4732] [debug] GET "/" (cd726066)
:44.91768] [4732] [debug] Routing to a callback
:45.10940] [4732] [debug] Rendering template "index.html.ep" from DATA section
:45.11445] [4732] [debug] Rendering template "menu.html.ep" from DATA section
:45.11736] [4732] [debug] Rendering template "datarows.html.ep" from DATA section
:45.16243] [4732] [debug] 200 OK (0.245983s, 4.065/s)
:46.35749] [4732] [debug] GET "/tap" (f0cc47e0)
:46.36461] [4732] [debug] Routing to a callback
:46.36624] [4732] [debug] 101 Switching Protocols (0.008739s, 114.430/s)
:46.36646] [4732] [debug] WS for table append opened
:58.41381] [4732] [debug] Rendering cached template "datarows.html.ep" from DATA section
:58.41454] [4732] [debug] html sent; new id = 231378


The problem occurred when switching from Mojolicious::Lite to the full version.

Server log looks like this:

at http://127.0.0.1:3000
:17.64413] [6264] [debug] GET "/" (5b7cd6b9)
:17.64681] [6264] [debug] Routing to controller "MyApp::Controller::FrontEnd" and action "index"
:17.83067] [6264] [debug] Rendering template "front_end/index.html.ep"
:17.83547] [6264] [debug] Rendering template "menu.html.ep"
:17.83944] [6264] [debug] Rendering template "datarows.html.ep"
:17.88862] [6264] [debug] Rendering template "layouts/default.html.ep"
:17.89673] [6264] [debug] 200 OK (0.252574s, 3.959/s)
:19.47888] [6264] [debug] GET "/tap" (2727832e)
:19.48026] [6264] [debug] Action "tap" is not allowed
:19.48132] [6264] [debug] Template "front_end/tap.html.ep" not found
:19.48225] [6264] [debug] Template "not_found.development.html.ep" not found
:19.48310] [6264] [debug] Template "not_found.html.ep" not found
:19.48413] [6264] [debug] Rendering template "mojo/debug.html.ep"
:19.53478] [6264] [debug] 404 Not Found (0.055844s, 17.907/s)

In the Lite app theris function call

websocket '/tap' => sub {
   
my $c = shift;

   
#get some data from outside
   
#...


# as the test showed, this is not necessary for lite app
#    $c->on(message => sub {
#    });

   
my $id = Mojo::IOLoop->recurring(3 => sub {

        #check for the new data
        #...
     
        if (new data found) {
            ...

           
my $html = $c->render_to_string('datarows');
            $c
->send($html);
            $c
->app->log->debug("html sent; new id = $max_id");
       
}
   
});

    $c
->on(finish => sub {
       
Mojo::IOLoop->remove($id);
        $c
->app->log->debug("WS for table append closed");
   
});

    $c
->app->log->debug('WS for table append opened');
};


This is transforms to couple parts in full app code.
In startup function

    $r->websocket('/tap')->to('front_end#tap');

In the FrontEnd controller:

sub tap {
   
my $self = shift;

   
# get some data
    #...


   
my $id = Mojo::IOLoop->recurring(3 => sub {
       
        # check for data

       
# if found
       
if (...) {
            ...

        #all the same
};


Why was he asking about a nonexistent template?

Stefan Adams

unread,
Sep 13, 2019, 1:46:54 AM9/13/19
to mojolicious
Try an action name other than `tap`.  tap() is a method in Mojo::Base which just about every class in Mojolicious inherits from.

In the Mojolicious::Lite app, you do not have a subroutine action named `tap` -- you just have a callback.  In the full Mojolicious app, you have a subroutine action named `tap`.  Specifically, these keywords are hidden from the router.

--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mojolicious/d6b383e5-b1d4-4cd2-bf4f-ef2fc0e99e71%40googlegroups.com.

Vadim N

unread,
Sep 13, 2019, 6:54:39 AM9/13/19
to Mojolicious

it worked ))

Thank you very much!


пятница, 13 сентября 2019 г., 12:46:54 UTC+7 пользователь Stefan Adams написал:
To unsubscribe from this group and stop receiving emails from it, send an email to mojol...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages