Mojolicious is not capturing URL (only base url)

梦想的初衷 提交于 2019-12-10 18:37:52

问题


I created a simple API using mojolicious, but I've just migrated from Apache to Nginx and cannot figure out how to handle url correctly

Here is my Server Block configuration file

server {
    listen 80;
    listen [::]:80;
    root /var/www/example.com/public_html;
    index index.pl index.html index.htm index.nginx-debian.html;

    server_name example.com www.example.com;

    location / {
            gzip off;
            include /etc/nginx/fastcgi_params;
            fastcgi_pass  127.0.0.1:8090;
            fastcgi_param SCRIPT_FILENAME /var/www/example/public_html/$fastcgi_script_name;
        }
}

It is handled by Mojolicious but I get following result.

Method: GET
URL:    
Base URL: http://example.com/clients/

As you can see base url is captured ,but URL is empty.

My pattern is

Pattern Methods Name
/clients GET clients

What is wrong ? How can I handle requests correctly ?


回答1:


I have faced with the same problem. I have found the following solution.

app->hook(before_dispatch => sub {
        my $c = shift;
        $c->tx->req->url->path->{'path'} = @{$c->tx->req->env}{'REQUEST_URI'};
    });
app->start;

It is a quick and dirty solution, but it works.

Hope this helps.



来源:https://stackoverflow.com/questions/43290656/mojolicious-is-not-capturing-url-only-base-url

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