From eff66ef08f60daa3f637c937d4148cb864ec4e35 Mon Sep 17 00:00:00 2001 From: "roberto@sirius" Date: Mon, 13 Dec 2010 18:16:15 +0100 Subject: [PATCH] added router.lua --- router.lua | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 router.lua diff --git a/router.lua b/router.lua new file mode 100644 index 00000000..9730e0b5 --- /dev/null +++ b/router.lua @@ -0,0 +1,33 @@ +print("uWSGI Lua router") + +uwsgi.log("i am ready") + +function route(env) + + print(env.REQUEST_URI) + + html = uwsgi.cache_get(env.REQUEST_URI) + + local function send_cache() + coroutine.yield(html) + end + + local function body() + page = "" + parts = { uwsgi.send_message("127.0.0.1:3033", 0, 0, env, 30, uwsgi.req_fd(), uwsgi.cl()) } + for i, part in pairs(parts) do + page = page .. part + coroutine.yield(part) + end + + uwsgi.cache_set(env.REQUEST_URI, page) + end + + if html then + return nil,{}, coroutine.wrap(send_cache) + end + + return nil,{}, coroutine.wrap(body) +end + +return route