Automating loading of index.html
Is there a way to be able to tell Dancer to load and index.html file automatically if it exists so be able to specify: http://l-sim-27-071:4080/todomvc/architecture-examples/yui rather than http://l-sim-27-071:4080/todomvc/architecture-examples/yui/index.html Mark Wood-Patrick ----------------------------------------------------------------------------------- This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. -----------------------------------------------------------------------------------
Couldn't you do this: get '/' => sub { template 'index.html' }; Jonathan Otsuka On Apr 27, 2013, at 6:56 PM, Mark Wood-Patrick <mwoodpatrick@nvidia.com> wrote:
Is there a way to be able to tell Dancer to load and index.html file automatically if it exists so be able to specify:
http://l-sim-27-071:4080/todomvc/architecture-examples/yui
rather than
http://l-sim-27-071:4080/todomvc/architecture-examples/yui/index.html
Mark Wood-Patrick
This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. _______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
I need to display index.html for any subdirectory where that file exists not just the root Mark From: dancer-users-bounces@dancer.pm [mailto:dancer-users-bounces@dancer.pm] On Behalf Of Jonathan Otsuka Sent: Saturday, April 27, 2013 5:00 PM To: Perl Dancer users mailing list Subject: Re: [dancer-users] Automating loading of index.html Couldn't you do this: get '/' => sub { template 'index.html' }; Jonathan Otsuka On Apr 27, 2013, at 6:56 PM, Mark Wood-Patrick <mwoodpatrick@nvidia.com <mailto:mwoodpatrick@nvidia.com> > wrote: Is there a way to be able to tell Dancer to load and index.html file automatically if it exists so be able to specify: http://l-sim-27-071:4080/todomvc/architecture-examples/yui rather than http://l-sim-27-071:4080/todomvc/architecture-examples/yui/index.html Mark Wood-Patrick _____ This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. _____ _______________________________________________ dancer-users mailing list dancer-users@dancer.pm <mailto:dancer-users@dancer.pm> http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
If the index.html is a static file, you will have to serve it from your public directory and then use the trick described here: http://modernperlbooks.com/mt/2011/08/serving-a-local-directory-with-plack.h... HTH On Sun, Apr 28, 2013 at 11:02 AM, Mark Wood-Patrick <mwoodpatrick@gmail.com>wrote:
I need to display index.html for any subdirectory where that file exists not just the root****
** **
Mark****
** **
*From:* dancer-users-bounces@dancer.pm [mailto: dancer-users-bounces@dancer.pm] *On Behalf Of *Jonathan Otsuka *Sent:* Saturday, April 27, 2013 5:00 PM *To:* Perl Dancer users mailing list *Subject:* Re: [dancer-users] Automating loading of index.html****
** **
Couldn't you do this:****
** **
get '/' => sub { template 'index.html' };
Jonathan Otsuka****
On Apr 27, 2013, at 6:56 PM, Mark Wood-Patrick <mwoodpatrick@nvidia.com> wrote:****
Is there a way to be able to tell Dancer to load and index.html file automatically if it exists so be able to specify:****
****
http://l-sim-27-071:4080/todomvc/architecture-examples/yui****
****
rather than****
****
http://l-sim-27-071:4080/todomvc/architecture-examples/yui/index.html ****
****
Mark Wood-Patrick ****
**** ------------------------------
This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. **** ------------------------------
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users****
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
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
That seemed to break regular URL's like /wishlist/mark But this does appear to work hook 'before' => sub { var note => 'Boo'; my $url = request->path_info(); $url =~ s/\/$//; $url .= "/index.html"; my $path = "$FindBin::RealBin/public$url"; if ( -r $path ) { return redirect $url } }; BTW are most folks using Dancer 2 or Dancer 1? Mark -----Original Message----- From: Jashank Jeremy [mailto:jashank@rulingia.com] Sent: Saturday, April 27, 2013 11:01 PM To: Mark Wood-Patrick Cc: Perl Dancer users mailing list Subject: Re: [dancer-users] Automating loading of index.html 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
participants (5)
-
Gurunandan Bhat -
Jashank Jeremy -
Jonathan Otsuka -
Mark Wood-Patrick -
Mark Wood-Patrick