Match any GET path with Mojolicious::Lite

谁说我不能喝 提交于 2021-02-19 03:39:06

问题


I’d like to match any GET request in Mojolicious::Lite. The code looks like this:

get '.*' => sub {
    my $self = shift;
    $self->render(text => 'Nothing to see here, move along.');
};

This dies with “Modification of non-creatable array value attempted” at MojoX::Routes::Pattern.pm, line 301. I tried other arguments to get, like qr//. That works for /, but does not match /foo. I also tried to peek at the source, but I’m none the wiser. Are you?


回答1:


I think you want:

get '/(*restofpath)' => ...

(The restofpath is a name that will allow you to retrieve the actual pathname later, should you need it...). For more details, look at the documentation for wilcard placeholders.



来源:https://stackoverflow.com/questions/3045799/match-any-get-path-with-mojoliciouslite

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!