We have an old Catalyst app, originally developed for Catalyst 5.7, then updated to Catalyst 5.8 a couple years ago.
Now we're trying to upgrade to Catalyst 5.9, and now calls to $c->uri_for() are not giving reasonable results, but only when run from lighttpd, and not when run from the stand-alone debug server.
I have stripped out all the application controllers except Root.pm
, and have turned it into a single sub:
package DCWeb::Controller::Root;
use strict;
use warnings;
use 5.10.0;
use Moose;
use namespace::autoclean;
BEGIN { extends 'Catalyst::Controller' }
__PACKAGE__->config->{namespace} = '';
sub foo :Path {
my ( $self, $c ) = @_;
$c->log->debug("Base: ".$c->req->base);
}
1;
When I run the code from the stand-alone debug server, I get the following debug output (correct):
Jul 9 15:09:51 dc8 dc-web: Base: http://localhost:3000/
When I run the same code through lighttpd with FastCGI (incorrect):
Jul 9 15:10:25 dc8 dc-web: Base: http://localhost:8080/foo/
I am using Catalyst 5.90015-1 from Debian wheezy. I attempted to upgrade to the latest, but some of the dependencies required a newer version of perl. Furthermore, the Changelog doesn't seem to mention any (obviously) relevant uri_for fixes.
I am therefore assuming there is some sort of breakage between lighttpd and Catalyst. But where do I go from here?
The answer appears to be that Catalyst 5.9 no longer does some necessary fixing of lighttpd-passed environment variables. This can be re-enabled using the Plack::Middleware/LighttpdScriptNameFix module.
I accomplished this by adding:
use Catalyst qw/
.
.
EnableMiddleware
/;
use Plack::Middleware::LighttpdScriptNameFix;
.
.
__PACKAGE__->config(
'Plugin::EnableMiddleware' => [
'LighttpdScriptNameFix',
],
);
Allegedly, with lighttpd 1.4.23 or later this can also be done by enabling the fix-root-scriptname
flag inside fastcgi.server in the lighttpd config, but this did not work for me.