• R/O
  • SSH
  • HTTPS

luatinycgi: Commit


Commit MetaInfo

Revision5 (tree)
Time2010-06-10 22:57:44
Authorsmeghead

Log Message

Ubuntu10.04で、サンプルの修正。サンプルの初期表示画面が表示されるようになった。

Change Summary

Incremental Difference

--- trunk/samples/webapp/lua/action/root.lua (revision 4)
+++ trunk/samples/webapp/lua/action/root.lua (revision 5)
@@ -1,12 +1,7 @@
11 module(..., package.seeall)
2-require "service.calc"
32
43 function index(request, response, path_infos, env)
5- env.message = request.QUERY.message
6- return {
7- forward = "./lp/index.lp",
8- env = env
9- }
4+ return {redirect = "/calc/index"}
105 end
116
127 -- vim: set ts=4 sw=4 sts=4 expandtab :
--- trunk/samples/webapp/site-lua/cgi.lua (revision 4)
+++ trunk/samples/webapp/site-lua/cgi.lua (revision 5)
@@ -92,9 +92,27 @@
9292 request = nil
9393 -- global variable
9494 response = nil
95-function init(env)
95+function init(env, action_dir)
96+ action_dir = action_dir or 'lua'
9697 request = Request.new()
9798 response = Response.new()
99+ -- load actions.
100+ require "lfs"
101+ local currentdir = lfs.currentdir()
102+ lfs.chdir(action_dir)
103+ for file in lfs.dir('action') do
104+ if string.match(file, "\.lua") then
105+ local action_file_path = string.format("action/%s", file:sub(0, string.len(file) - 4))
106+ cgi.log:debug('load file. ' .. action_file_path)
107+ local p = require(action_file_path)
108+ cgi.log:debug('loaded file. ' .. action_file_path)
109+ cgi.log:debug(p._NAME)
110+ cgi.log:debug(p._PACKAGE)
111+ for k,v in pairs(p) do
112+ end
113+ end
114+ end
115+ lfs.chdir(currentdir)
98116 end
99117 function destroy()
100118 cgi.request.session:close()
@@ -119,8 +137,9 @@
119137
120138 function get_action(subapp_name, action_name, env)
121139 local func = nil
122- local packagename = string.format("action.%s", subapp_name or '')
123- if packagename and action_name then
140+ local packagename = string.format("action/%s", subapp_name or 'root')
141+ action_name = action_name or 'index'
142+ if packagename then
124143 if package.loaded[packagename] and type(package.loaded[packagename][action_name]) == 'function' then
125144 func = package.loaded[packagename][action_name]
126145 elseif type(package.loaded[packagename]) == 'function' then
@@ -228,6 +247,7 @@
228247 if action then
229248 result = action(request, response, path_infos, env)
230249 else
250+ cgi.log:info('no action. ', request.url)
231251 response:file_not_found(request.url)
232252 cgi.destroy()
233253 os.exit(-1)
@@ -234,8 +254,11 @@
234254 end
235255
236256 if not result then
257+ cgi.log:debug('ok.')
258+ cgi.log:debug(result)
237259 -- do nothing.
238260 elseif result.error then
261+ cgi.log:debug('print error page.')
239262 response:error500(request.url)
240263 elseif result.forward then
241264 cgi.log:debug('forward to ' .. result.forward)
Show on old repository browser