
chunziatperlchina.org
Jul 16, 2005, 12:47 PM
Post #1 of 1
(807 views)
Permalink
|
when using Apache, sometimes we configed as: Alias /archieve /home/paht/to/some/archieve so, we could access the files under the long real path by http://example.com/archieve/some/files and in Catalyst, running with script/myapp_server.pl, almot use the Catalyst::Plugin::Static to serve the files under root directory. no alisa support. so I just wrote an extend as follow: package Catalyst::Plugin::StaticAlias; use base 'Catalyst::Plugin::Static'; sub serve_static { my $c = shift; my @params = @_; my @static_alias = @{$c->config->{'static_alias'}}; my @pairs; while ( @static_alias ){ my $alias_name = shift @static_alias; my $alias_path = shift @static_alias; next unless -d $alias_path; push @pairs, [ $alias_name, $alias_path ]; } my $req_path = $c->req->path; $req_path =~ s/^\///; foreach ( @pairs ){ my ( $alias_name, $alias_path ) = @{$_}; next unless $req_path =~ /^$alias_name/; $req_path =~ s/^$alias_name//; my $path = $alias_path. '/' . $req_path; return $c->serve_static_file( $path, @params ); } # default, as baseclass my $path = $c->config->{root} . '/' . $c->req->path; return $c->serve_static_file( $path, @params ); } 1; and in myapp's config like: use Catalyat 'StaticAlias'; myapp->config( static_alias => [ 'archieve' => '/home/chunzi/CaberMessages', ], ); that's a scrach, but works fine. and I think there more works to do to have a greate Static module. and I hope you could make it more better.
|