[Catalyst] serving static content from one controller?

Mitchell Jackson mitch.lists at onsitesquad.com
Fri Oct 5 16:53:13 GMT 2007

Static::Simple seems to have some configuration options to force certain 
paths as static only
Practical examples can be found here 

 MyApp->config->{static}->{dirs} = [

If you're serving your app under apache, you can set an Alias directive 
that bypasses catalyst for your static content.

        DocumentRoot  /var/www/APP/root
        Alias / /tmp/app.fcgi/
        Alias /static /var/www/APP/root/static

If you want to serve from your /public controller because static simple 
doesn't do something you want, you might use something like this

sub index : Private {
    my $self = shift;
    my $c    = shift;

    my $static_fn = $c->path_to( 'public', @_ );
    if ( -e $static_fn ) {
       $c->serve_static_file( $static_fn );
    else {
       $c->detach( 'error404' );
sub error404 : Private {
    my ( $self, $c ) = @_;
    $c->res->redirect( $c->uri_for('/'));

For more help, read over the documentation on deployment, starting with 
the cookbook:  


Dustin Suchter wrote:
> So I've got what has to be a pretty common problem: I've built a
> system that is 95% behind some authentication, and 5% public. I'd
> like to have the entire public portion be static HTML files that are
> all served from the '/public/' directory. I've created a "Public"
> controller and the corresponding directory to hold static HTML
> content. I've also modified the system such that either the Public
> controller or the Login controller can be access by unauthenticated
> users.
> How do I go about serving the static pages, for example my page
> "books_intro.html"?
> I've looked into "Static::Simple", but I can't find a good
> manual/tutorial on it. I've tried to guess at how to use it but I
> pretty much didn't get anywhere.
> thanks,
> -d
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
> Dev site: http://dev.catalyst.perl.org/

More information about the Catalyst mailing list