[Catalyst] static files without extensions

Jason Kohles email at jasonkohles.com
Fri Jan 4 01:02:57 GMT 2008


On Jan 3, 2008, at 3:24 PM, Emily Heureux wrote:

> (I am starting a brand new email, not replying to an existing one,  
> which I now realize I have been doing, but maybe not every time.  Am  
> I sending these to the wrong place?  The address I have is catalyst at lists.scsys.co.uk 
> .  Did I do it right this time?)
>
> My question:  I have a directory under root:  /static/images/ 
> pdbFiles where I have files without extensions for a java applet I  
> am running on my webpage.  Catalyst does not seem to recognize them  
> unless I put an extension, like .txt.  Do I need to configure  
> Catalyst so that it sees those files as static files?
>
> On cpan, I found that I can force directories into static mode using  
> this (for example):
>
> MyApp->config->{static}->{dirs} = [
>         'static',
>         qr/^(images/pdbFiles|)/,
>     ];
>
> but, where do I put this code, if that is, in fact, what I am  
> supposed to do?  And since I want it to work for files with no  
> extensions, what do I put after the pipe?

If you already have your files in /static, then it will do what you  
want by default.  The problem is that without an extension,  
Static::Simple can't determine the correct MIME type, so it uses text/ 
html.  One approach to handling this is to subclass  
Catalyst::Plugin::Static::Simple and override _ext_to_type so it  
returns the correct MIME type for those files...


package MyApp::Plugin::Static::Simple;
use strict;
use warnings;
use base qw( Catalyst::Plugin::Static::Simple );

sub _ext_to_type {
	my ( $self, $path ) = @_;

	if ( $path =~ /pdbFiles/ ) {
		return 'application/x-java-applet';
	} else {
		return $self->SUPER::_ext_to_type( $path );
	}
}

1;

Then in your application class...

use Catalyst qw(
	+MyApp::Plugin::Static::Simple
	Session Cache Whatever...
);

-- 
Jason Kohles, RHCA RHCDS RHCE
email at jasonkohles.com - http://www.jasonkohles.com/
"A witty saying proves nothing."  -- Voltaire


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20080103/197cc868/attachment-0001.htm


More information about the Catalyst mailing list