Add native support for homepages
authorSteven Barth <steven@midlink.org>
Mon, 27 Jul 2009 12:09:46 +0000 (12:09 +0000)
committerSteven Barth <steven@midlink.org>
Mon, 27 Jul 2009 12:09:46 +0000 (12:09 +0000)
libs/lucid-http/luasrc/lucid/http/LuciWebPublisher.lua
libs/lucid-http/luasrc/lucid/http/server.lua
libs/lucid/hostfiles/etc/config/lucid
libs/lucid/root/etc/config/lucid

index f72b94f..92dd7e2 100644 (file)
@@ -56,11 +56,18 @@ function factory(server, config)
                end
        end
 
                end
        end
 
+       local mypath
        if type(config.virtual) == "table" then
                for _, v in ipairs(config.virtual) do
        if type(config.virtual) == "table" then
                for _, v in ipairs(config.virtual) do
+                       mypath = mypath or v
                        vhost:set_handler(v, handler)
                end
        else
                        vhost:set_handler(v, handler)
                end
        else
+               mypath = config.virtual
                vhost:set_handler(config.virtual, handler)
        end
                vhost:set_handler(config.virtual, handler)
        end
+
+       if config.home then
+               vhost.default = mypath
+       end
 end
\ No newline at end of file
 end
\ No newline at end of file
index cb10813..eb6f6f5 100644 (file)
@@ -198,6 +198,10 @@ function VHost.process(self, request, ...)
        -- Call URI part
        request.env.PATH_INFO = uri
        
        -- Call URI part
        request.env.PATH_INFO = uri
        
+       if self.default and uri == "/" then
+               return 302, {Location = self.default}
+       end
+
        for k, h in pairs(self.handlers) do
                if #k > hlen then
                        if uri == k or (uri:sub(1, #k) == k and uri:byte(#k+1) == sc) then
        for k, h in pairs(self.handlers) do
                if #k > hlen then
                        if uri == k or (uri:sub(1, #k) == k and uri:byte(#k+1) == sc) then
index 934faa1..22b7efa 100644 (file)
@@ -19,6 +19,7 @@ config LuciWebPublisher luciweb
        option physical ''
        list virtual /luci
        option domain ''
        option physical ''
        list virtual /luci
        option domain ''
+       option home 1
        list exec ':lo'
        list exec ':br-lan'
        list exec 'root'
        list exec ':lo'
        list exec ':br-lan'
        list exec 'root'
@@ -71,4 +72,3 @@ config 'Redirector' 'splashredir'
         option 'virtual' '/'
         option 'physical' ':80/luci/splash'
 
         option 'virtual' '/'
         option 'physical' ':80/luci/splash'
 
-       
\ No newline at end of file
index c5a3f3d..07c32c1 100644 (file)
@@ -15,6 +15,7 @@ config DirectoryPublisher webroot
 config LuciWebPublisher luciweb
        option name 'LuCI Webapplication'
        option physical ''
 config LuciWebPublisher luciweb
        option name 'LuCI Webapplication'
        option physical ''
+       option home 1
        list virtual /luci
        list virtual /cgi-bin/luci
        option domain ''
        list virtual /luci
        list virtual /cgi-bin/luci
        option domain ''