summaryrefslogtreecommitdiff
path: root/examples/router.lua
blob: 9730e0b5593c1f990b4c91af5eb6fd0a753cd580 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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