Discussion:
[Mason-devel] Fwd: Dealing with index.html and multiple-component roots
Pedro Melo
2010-09-08 11:33:54 UTC
Permalink
Hi,

I sent this to the Mason-Users list, but I should probably use the
Mason-devel list.

Thanks,


---------- Forwarded message ----------
From: Pedro Melo <***@simplicidade.org>
Date: Tue, Sep 7, 2010 at 11:50 AM
Subject: Re: Dealing with index.html and multiple-component roots
To: mason-***@lists.sourceforge.net


Hi again,

just to experiment with the idea, I wrote this quick & dirty patch.
Its in the "it works for me but I'm not putting this into production
without more tests"-state.

---- 8< ------
diff --git a/elib/html-mason/lib/HTML/Mason/Request.pm
b/elib/html-mason/lib/HTML/Mason/Request.pm
index 003e154..4479423 100644
--- a/elib/html-mason/lib/HTML/Mason/Request.pm
+++ b/elib/html-mason/lib/HTML/Mason/Request.pm
@@ -249,6 +249,11 @@ sub _initialize {
            search: {
                $request_comp = $self->interp->load($path);

+                ## FIXME: index.html should be a configuration parameter
+                unless ($request_comp) {
+                    $request_comp = $self->interp->load("$path/index.html");
+                }
+
                last search unless $self->use_dhandlers;

                # If path was not found, check for dhandler.
---- 8< ------
Hi,
I'm revisiting a very old Mason site (still running 1.05, I'm
upgrading it to the latest Mason) and I stumbled on something about
serving index.html files and multiple component roots.
This sites uses a "common" and "channel" component setup. Its the same
basic site, shared with different output channels. Each channel has
its on component root and it appears first in the list of component
roots, so that each site can override the common one.
The Apache document root points to the channel document root, and the
Apache configuration uses a DocumentIndex directive to set the
index.html file as the one to get on directory URLs.
But if I move all index.html components to the common component root
(outside the Apache document root), the /dir/ => /dir/index.html
internal rewrite will not happen, because there is no /dir/ nor
/dir/index.html in the Apache document root.
The question is: do you have a similar setup that is working? If so how?
I searched the docs and I found about decline_dirs setting that might
help me but it seems that I would need to create a dhandler for each
directory where I have an index.html file.
Looking at the code it seems that Mason doesn't deal with this
situation at all. Maybe moving the Apache "DirectoryIndex" setting to
Mason would make some sense, given that right now it doesn't seem to
be able to deal with multiple component roots? If so, would you accept
a patch for it?
Thanks in advance,
--
Pedro Melo
http://www.simplicidade.org/
xmpp:***@simplicidade.org
mailto:***@simplicidade.org
Ask Bjørn Hansen
2010-09-13 09:11:37 UTC
Permalink
Hi everyone,

I just subscribed now to post a different question but wanted to follow-up to Melo's post from last week re "index.html" file handling.

I'm migrating a project off Apache and ran into the same need -- "emulate" the Apache handling of this in Mason; so I'm all for the change to support it (although not exactly like Melo suggested; but I agree with the goal).


- ask
Pedro Melo
2010-09-13 09:55:41 UTC
Permalink
Hi
Post by Ask Bjørn Hansen
I just subscribed now to post a different question but wanted to follow-up to Melo's post from last week re "index.html" file handling.
I'm migrating a project off Apache and ran into the same need -- "emulate" the Apache handling of this in Mason; so I'm all for the change to support it (although not exactly like Melo suggested; but I agree with the goal).
Yes, I'm not claiming that my "patch" is the best solution, in fact it
was a plea for a better solution :)

Right now, I'm running my patch on my staging environment. I've needed
to tweak my Apache installation a bit (if you have an empty directory
in the document root/first component root and the index.html is in the
second component root, you get a request with mime/type
httpd/unix-directory that you must map to text/html for example).

So, it feels that I'm hacking away until something that I can use in
production but what I'll end up with is a very shaky foundation, and I
would like to see a more stable solution.

Thanks,
--
Pedro Melo
http://www.simplicidade.org/
xmpp:***@simplicidade.org
mailto:***@simplicidade.org
Ask Bjørn Hansen
2010-09-13 10:25:12 UTC
Permalink
On Sep 13, 2010, at 2:55, Pedro Melo wrote:

I didn't try it, but what I'd try if I wasn't going to sleep several hours ago (doh) would be modifying get_info in HTML::Mason::Resolver::File to add "/index.html" if $srcfile is a directory. (Where index.html is configured somehow).

(This doesn't take care of redirects from /dir to /dir/ - that'd be somewhere else...).


- ask
--
Ask Bjørn Hansen, http://askask.com/
Pedro Melo
2010-09-13 15:17:18 UTC
Permalink
Hi,
I didn't try it, but what I'd try if I wasn't going to sleep several hours ago (doh) would be modifying get_info in HTML::Mason::Resolver::File to add "/index.html" if $srcfile is a directory.  (Where index.html is configured somehow).
I'll try it that way to see if its simpler.
(This doesn't take care of redirects from /dir to /dir/ - that'd be somewhere else...).
Not sure where...

Bye,
--
Pedro Melo
http://www.simplicidade.org/
xmpp:***@simplicidade.org
mailto:***@simplicidade.org
Loading...