I'm learning web development with lua (wsapi and uWSGI). I'm trying to create a request object (https://keplerproject.github.io/wsapi/libraries.html) to see what it look like (and how to use it). So I've set up a example code :
require "wsapi.cgi"
function run(wsapi_env)
local headers = { ["Content-type"] = "text/html" }
local function hello_text()
local result = "<html><body>\n"
result = result .. "<p> Hello Wsapi !</p>\n"
result = result .. "<p>PATH_INFO wsapi_env: " .. wsapi_env.PATH_INFO .. "</p>\n"
-- problematic code
local req = wsapi.request.new(wsapi_env)
if req
then
--condition to see if req was nill
result = result .. "<p>PATH INFO_POST : " .. req.POST .. "</p>\n"
result = result .. "<p>PATH INFO_GET : " .. req.GET .. "</p>\n"
else
result = result .. "<p> No request <\p>\n"
end
-- end of the problematic code
result = result .. "<p><form method=\"post\" action=\"hello.lua\">\n"
result = result .. "<textarea name=\"message\"> test </textarea>\n"
result = result .. "</form></p>\n"
result = result .. "</body></html>\n"
coroutine.yield(result)
end
return 200, headers, coroutine.wrap(hello_text)
end
return run
But when I use the request object, the client receive a blank page.
How can I create and use a request object ?
Thanks you for your answers !
Extra question : How do I redirect to another page ( to a static page on the same domain ) ?