FAQ
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

Search Discussions

  • Jonathan Rockway at Oct 5, 2007 at 7:09 am

    Dustin Suchter wrote:
    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.
    This is probably not the best idea. It would be better for your
    Catalyst app to inform your web server as to what static page to serve.
    perlbal calls this an "internal redirect", and lighttpd calls it
    "X-SendFile". Please look into those; all your cat app will have to do
    is send an HTTP header with the name of the file, and the web server
    will take care of the rest.

    This has come up before, I think, so grep the list archives for more detail.

    Failing that, you can always set $c->res->body to a filehandle:

    sub send_static :Private {
    my ($self, $c, $filename) = @_;
    open my $fh, '<', $filename or die "failed to open $filename: $!";
    $c->res->body($fh);
    $c->detach;
    }

    Hopefully the internal redirects will work out for you, though. Good luck.

    Regards,
    Jonathan Rockway

    -------------- next part --------------
    A non-text attachment was scrubbed...
    Name: signature.asc
    Type: application/pgp-signature
    Size: 370 bytes
    Desc: OpenPGP digital signature
    Url : http://lists.scsys.co.uk/pipermail/catalyst/attachments/20071005/b466c53e/signature.pgp
  • Ash Berlin at Oct 5, 2007 at 8:12 am

    Jonathan Rockway wrote:
    Dustin Suchter wrote:
    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.
    This is probably not the best idea. It would be better for your
    Catalyst app to inform your web server as to what static page to serve.
    perlbal calls this an "internal redirect", and lighttpd calls it
    "X-SendFile". Please look into those; all your cat app will have to do
    is send an HTTP header with the name of the file, and the web server
    will take care of the rest.

    This has come up before, I think, so grep the list archives for more detail.

    Failing that, you can always set $c->res->body to a filehandle:

    sub send_static :Private {
    my ($self, $c, $filename) = @_;
    open my $fh, '<', $filename or die "failed to open $filename: $!";
    $c->res->body($fh);
    $c->detach;
    }

    Hopefully the internal redirects will work out for you, though. Good luck.

    Regards,
    Jonathan Rockway
    Another option instead of using X-SendFile for lighttpd is to do as I
    describe in http://perlitist.com/articles/catalyst-with-lighttpd

    If you are using apache and want to achieve something similar with
    static files let me know and I can show you the config you'd need to get
    the same affect (Apache to serve the static stuff)

    -ash
  • Bernhard Graf at Oct 5, 2007 at 10:21 am

    On Friday 05 October 2007 09:12, Ash Berlin wrote:
    Jonathan Rockway wrote:
    Dustin Suchter wrote:
    Another option instead of using X-SendFile for lighttpd is to do as I
    describe in http://perlitist.com/articles/catalyst-with-lighttpd

    If you are using apache and want to achieve something similar with
    static files let me know and I can show you the config you'd need to
    get the same affect (Apache to serve the static stuff)
    Or a bit simpler as in
    http://search.cpan.org/dist/Catalyst-Manual/lib/Catalyst/Manual/Cookbook.pod#Static_file_handling

    --
    Bernhard Graf
  • Dustin Suchter at Oct 5, 2007 at 12:45 pm
    Thanks for all the replies- best mailing list ever.

    Anyway, I'm planning on running lighttpd, but to date I've just been
    developing with the built in Catalyst server since I've had a bit of
    an issue getting FastCGI/lighttpd working right on my server. I
    guess it is time to fix that and then implement the solution to my
    question here...

    thanks again everyone,
    -d

    Ash Berlin wrote:
    Jonathan Rockway wrote:
    Dustin Suchter wrote:
    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.
    This is probably not the best idea. It would be better for your
    Catalyst app to inform your web server as to what static page to serve.
    perlbal calls this an "internal redirect", and lighttpd calls it
    "X-SendFile". Please look into those; all your cat app will have to do
    is send an HTTP header with the name of the file, and the web server
    will take care of the rest.

    This has come up before, I think, so grep the list archives for more detail.

    Failing that, you can always set $c->res->body to a filehandle:

    sub send_static :Private {
    my ($self, $c, $filename) = @_;
    open my $fh, '<', $filename or die "failed to open $filename: $!";
    $c->res->body($fh);
    $c->detach;
    }

    Hopefully the internal redirects will work out for you, though. Good luck.

    Regards,
    Jonathan Rockway
    Another option instead of using X-SendFile for lighttpd is to do as I
    describe in http://perlitist.com/articles/catalyst-with-lighttpd

    If you are using apache and want to achieve something similar with
    static files let me know and I can show you the config you'd need to get
    the same affect (Apache to serve the static stuff)

    -ash

    _______________________________________________
    List: Catalyst@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/
  • Bill Moseley at Oct 5, 2007 at 3:34 pm

    On Thu, Oct 04, 2007 at 07:34:43PM -0700, 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.
    Are the static html files generated via templates? That is, are they
    really "static" or do they just not contain any dynamic content but
    still must be processed by catalyst to generate the page?

    For static pages that are still built with templates and Catalyst I
    use a caching proxy in front of Catalyst.
    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.
    You mean the C::P::Static::Simple manual wasn't helpful?
    How did you set it up?

    --
    Bill Moseley
    moseley@hank.org
  • Mitchell Jackson at Oct 5, 2007 at 4:53 pm
    Static::Simple seems to have some configuration options to force certain
    paths as static only
    Practical examples can be found here
    http://search.cpan.org/~jrockway/Catalyst-Manual-5.701002/lib/Catalyst/Manual/Cookbook.pod#Serving_static_content

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



    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('/'));
    $c->detach();
    }

    For more help, read over the documentation on deployment, starting with
    the cookbook:
    http://search.cpan.org/~jrockway/Catalyst-Manual-5.701002/lib/Catalyst/Manual/Cookbook.pod#Deployment

    /Mitch

    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@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/

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedOct 5, '07 at 3:32a
activeOct 5, '07 at 4:53p
posts7
users6
websitecatalystframework.org
irc#catalyst

People

Translate

site design / logo © 2022 Grokbase