Search code examples
perlstaticcatalyst

Catalyst config when static data referenced by boilerplate HTML


we want to build a site HABJ (*) starting from some HTML 'demo' pages that have been produced externally : 'lorem ipsum' stuff. I've given these raw HTML files a .tt extension, put them in ...root/static/tt/page-this.tt etc, configured the app with

 HABJ/View/TT.pm:11:    INCLUDE_PATH => [ HABJ->path_to('root','tt') ]

and I am thrashing a bit trying to get the references to css, images, js to be handled by the static configuration

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

 \__PACKAGE__->config(
           static => {
               include_path => [
                   __PACKAGE__->config->{root},
                   '/root/static',
                   '/root/static/css',
                   '/root/static/js',
                   '/root/static/images',
               ],
           },
       );

but all references to css and images are 404'ed

 [debug] "GET" request for "css/all.css" from "xx.xx.xx.xx"
 [debug] Path is "/"
 [debug] Arguments are "css/all.css"
 [debug] Response Code: 404; Content-Type: text/html; charset=utf-8; Content-Length: 14


 [debug] "GET" request for "images/ico15.gif" from "xx.xx.xx.xx"
 [debug] Path is "/"
 [debug] Arguments are "images/ico15.gif"
 [debug] Response Code: 404; Content-Type: text/html; charset=utf-8; Content-Length: 14

Under Apache it serves up fine, with FastCGI set up thus

    Alias /static /usr/local/lib/Catalyst/HABJ/root/static
    Alias /css    /usr/local/lib/Catalyst/HABJ/root/static/css
    Alias /images /usr/local/lib/Catalyst/HABJ/root/static/images
    Alias /js     /usr/local/lib/Catalyst/HABJ/root/static/js
    Alias /       /usr/local/lib/Catalyst/HABJ/script/habj_fastcgi.pl/

Now I 'know' that if we were generating the tt files ourselves from scratch it probably wouldn't be like this. But can someone tell me what I need to get the Cat server to handle this?

thanks...

(*) I know what you're thinking. Don't go there.


Solution

  • Just like your Apache/FastCGI setup, your include_path should be fully qualified, ie:

    include_path => [
           '/path/to/root',
           ...
    ],
    

    Assuming that the static directory is immediately under the root, so a request for /static/my.css translates to /path/to/root/static/my.css

    Obviously you would use an environment or config variable rather than an explicit, server-specific path.