Tuesday, July 28, 2009

Serving static files with Catalyst

Serving static javascript files from Catalyst can be a hassle. URLs don't match etc.

If instead you change your MyApp.pm file as follows

__PACKAGE__->config->{static}->{dirs} = [
'static',
qr/^(images|css|js)/,
];

and you place your javascript files in the MyApp/root/js directory, the hassle's gone.

Even better, if you don't have application specific files, you can symlink the directory to the one where you keep the same files to be served by Lighttpd.

Catalyst FastCGI in a directory

This configuration allows you to have multiple applications run separately from a single Lighttpd instance, by dispatching to them based on the root directory.

This way it's easier to update single parts, and debug them separately.


#----------------------------------------------------------------------------
# this is a lighttpd configuration file for a Catalyst FCGI application
# that lives within a directory
#----------------------------------------------------------------------------

#-----------------------------------------
# ensure there's always a trailing slash
#-----------------------------------------
url.rewrite-once = (
"^/(skunky)$" => "/$1/",
)

#-----------------------------------------
# forward requests to the FCGI server
#-----------------------------------------
$HTTP["url"] =~ "^/skunky" {
alias.url = (
# app-specific favicon (does this work?)
"/favicon.ico" => "/var/www/Skunky/favicon.ico",
# standard js
"/js/" => "/var/www/js/",
# app-specific css
"/css/" => "/var/www/Skunky/css/",
)

# fcgi - does not rewrite the script name
fastcgi.server = (
"/skunky" => (
( "host" => "127.0.0.1", "port" => 3012, "check-local" => "disable"),
)
)
}