[dancer-users] Automating loading of index.html

Jashank Jeremy jashank at rulingia.com
Sun Apr 28 07:01:09 BST 2013


G'day,

On Sat, Apr 27, 2013 at 10:32:20PM -0700, Mark Wood-Patrick wrote:
>I need to display index.html for any subdirectory where that file
>exists not just the root

I suspect you probably want to look at the way that `auto_page` is
implemented, although you may need to appropriate and modify it: in D1,
it's render_autopage and _autopage_response in `Dancer::Renderer`, and
in D2, it's in `Dancer2::Handler::AutoPage`.

I can't really think of any other ways to do it off-hand, other than
with a catch-all route, but that would fall over, I suspect, if you
needed a route at `/todomvc/architecture-examples/yui` as well as at
`/todomvc/architecture-examples/yui/index.html`.  A route something like

    get qr{(.*)} => sub {
        my ($path) = splat;
        return redirect $path."/index.html"
            if -e settings('views_dir').$path."/index.html";
        return send_error(404);
    };

-- assuming a setting, `views_dir`, pointing at your views directory;
alternately, `setting('appdir')."/views"` should work, given a fairly
standard setup -- should work.

Jashank

--
Jashank Jeremy
WWW	rulingia.com/~jashank
PGP	D05D79F1 41DA2FB5 233E0565 ACC5E467 25A5C309
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 235 bytes
Desc: not available
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20130428/51d3bb64/attachment.pgp>


More information about the dancer-users mailing list