From e91905234bddeaa127b17942b2fa1e87de387ded Mon Sep 17 00:00:00 2001 From: Felipe Daragon Date: Sun, 27 Sep 2015 18:47:18 -0300 Subject: [PATCH] Make Lighttpd support work again --- src/remy.lua | 5 +++-- src/remy/mod_magnet.lua | 3 ++- src/sailor.lua | 20 ++++++++++++++------ src/sailor/blank-app/index-magnet.lua | 10 +++++++--- test/dev-app/index-magnet.lua | 10 +++++++--- 5 files changed, 33 insertions(+), 15 deletions(-) diff --git a/src/remy.lua b/src/remy.lua index 4c7c20d..8d12fee 100644 --- a/src/remy.lua +++ b/src/remy.lua @@ -1,4 +1,4 @@ --- Remy 0.2.8 +-- Remy 0.2.9 -- Copyright (c) 2014-2015 Felipe Daragon -- License: MIT (http://opensource.org/licenses/mit-license.php) -- @@ -133,7 +133,8 @@ function remy.detect(native_request) if env["pLua-Version"] ~= nil then mode = remy.MODE_MOD_PLUA end - elseif package.loaded.lighty ~= nil then + -- Note: lighty is not a package so package.loaded.lighty ~= nil will not work + elseif lighty ~= nil then mode = remy.MODE_LIGHTTPD elseif native_request ~= nil and type(native_request.query_param) == "function" then mode = remy.MODE_LWAN diff --git a/src/remy/mod_magnet.lua b/src/remy/mod_magnet.lua index 9ecf558..d6e3fa4 100644 --- a/src/remy/mod_magnet.lua +++ b/src/remy/mod_magnet.lua @@ -4,7 +4,8 @@ local base64 = require "base64" local remy = require "remy" -local lighty = require "lighty" +-- local lighty = require "lighty" +-- Note: lighty is not a package so require "lighty" will not work local utils = {} diff --git a/src/sailor.lua b/src/sailor.lua index 3486303..813cca9 100755 --- a/src/sailor.lua +++ b/src/sailor.lua @@ -56,15 +56,23 @@ function sailor.handle_request(r) return sailor.route(page) end +function sailor.get_filename_path(r) + local filename = r.uri:match( "([^/]+)$") + return r.filename:match("^@?(.-)/"..filename.."$") +end + -- Stores the path of the application in sailor.path function sailor.set_application_path(r) - local dir = lfs.currentdir() - - if dir == '/' or not dir then - local filename = r.uri:match( "([^/]+)$") - sailor.path = r.filename:match("^@?(.-)/"..filename.."$") + if sailor.remy_mode == remy.MODE_LIGHTTPD then + -- Ideally, this should not be needed (needs improvement/removal) + sailor.path = sailor.get_filename_path(r) else - sailor.path = dir + local dir = lfs.currentdir() + if dir == '/' or not dir then + sailor.path = sailor.get_filename_path(r) + else + sailor.path = dir + end end end diff --git a/src/sailor/blank-app/index-magnet.lua b/src/sailor/blank-app/index-magnet.lua index 76e0b2a..e45e62a 100644 --- a/src/sailor/blank-app/index-magnet.lua +++ b/src/sailor/blank-app/index-magnet.lua @@ -1,12 +1,16 @@ -- Alternative index for LightTPD's mod_magnet -if package.loaded.lighty ~= nil then - local lighty = require "lighty" +if lighty ~= nil then + -- Note: package.loaded.lighty ~= nil will not work because lighty is a + -- local variable and not a package local docroot = lighty.env['physical.doc-root'] package.path = package.path..";"..docroot.."/../lib/lua/?.lua" package.cpath = package.cpath..";"..docroot.."/../lib/clibs/?.dll" package.path = package.path..";"..docroot.."/sailor/?.lua" - + + -- Makes lighty global so it can be accessed by Remy or controllers + _G["lighty"] = lighty local sailor = require "sailor" sailor.launch() return sailor.r.status end + diff --git a/test/dev-app/index-magnet.lua b/test/dev-app/index-magnet.lua index 76e0b2a..e45e62a 100644 --- a/test/dev-app/index-magnet.lua +++ b/test/dev-app/index-magnet.lua @@ -1,12 +1,16 @@ -- Alternative index for LightTPD's mod_magnet -if package.loaded.lighty ~= nil then - local lighty = require "lighty" +if lighty ~= nil then + -- Note: package.loaded.lighty ~= nil will not work because lighty is a + -- local variable and not a package local docroot = lighty.env['physical.doc-root'] package.path = package.path..";"..docroot.."/../lib/lua/?.lua" package.cpath = package.cpath..";"..docroot.."/../lib/clibs/?.dll" package.path = package.path..";"..docroot.."/sailor/?.lua" - + + -- Makes lighty global so it can be accessed by Remy or controllers + _G["lighty"] = lighty local sailor = require "sailor" sailor.launch() return sailor.r.status end +