1 | profess = {} |
2 |
|
3 | if not ngx then |
4 | print("FATAL ERROR: no ngx module. Are you using ngx_lua (OpenResty)?") |
5 | return 1 |
6 | end |
7 |
|
8 | profess.version_major = 0 |
9 | profess.version_minor = 1 |
10 | profess.version_patch = 0 |
11 | profess.version_string = string.format("profess/%d.%d.%d", profess.version_major, profess.version_minor, profess.version_patch) |
12 |
|
13 | ngx.header.Content_Type = "text/html" |
14 | ngx.header.Server = profess.version_string |
15 | ngx.say("<html><head><title>aaaaa</title></head><body>") |
16 | ngx.say("<h1>hello from " .. profess.version_string .. "</h1>") |
17 | ngx.say("<p>Running Lua version " .. _VERSION .." (LuaJIT)</p>") |
18 | ngx.say("<p>Running nginx version " .. string.format("%d.%d.%d", ngx.config.nginx_version/1000000, ngx.config.nginx_version/1000%1000, ngx.config.nginx_version%1000) .."</p>") |
19 | ngx.say("<p>Running ngx_lua version " .. string.format("%d.%d.%d", ngx.config.ngx_lua_version/1000000, ngx.config.ngx_lua_version/1000%1000, ngx.config.nginx_version%1000) .."</p>") |
20 | ngx.say("<p>nginx worker " .. tostring(ngx.worker.pid()) .. "</p>") |
21 | for i=0,1000 do ngx.say("a") end |
22 | ngx.say("</body></html>") |
23 | ngx.exit(ngx.HTTP_OK) |
24 |
|
25 | local profess = require("profess") |
26 | local app = profess.app() |
27 |
|
28 | app.authorize("") |
29 |
|
30 | app.rewrite("^/(.*)/$", "/$1") -- rewrite trailing slashes |
31 |
|
32 | app.route("/", function(req, res) |
33 | res.status = 200 |
34 | res.head.content_type = "text/html" |
35 |
|
36 | res.write("<h1>Hello, World!</h1>") |
37 |
|
38 | res.write("<h2>Server Diagnostics</h2>", endl='') -- no newline |
39 | res.write("<p>Running profess version "..profess.version..", " |
40 | .."nginx version "..app.nginx_version..", " |
41 | .."Lua version "..app.lua_version..", " |
42 | .."ngx_lua version "..app.ngx_lua_version.."</p>") |
43 | res.write("<p>nginx worker ID "..tostring(app.worker.id).."</p>") |
44 |
|
45 | res.write("<h2>Request cookies</h2>") |
46 | for name, value in pairs(req.cookies) do |
47 | res.write( |
48 | string.format("<p>%s: %s</p>", name, value) |
49 | ) |
50 | end |
51 |
|
52 | res.finish() -- This relays the response to OpenResty and exits the program |
53 | end) |
54 |
|
55 | app.route("/", function(req, res) --[[...]] end) -- all of these |
56 | app.route("/", "GET", function(req, res) --[[...]] end) -- calls are the |
57 | app.get("/", function(req, res) --[[...]] end) -- same |
58 |
|
59 | app.code_route("/api", 404, function(req, res) --[[...]] end) |
60 | app.code_route("/api", 405, function(req, res) --[[...]] end) |
61 | app.code_default(404, function(req, res) --[[...]] end) |
62 | app.code_default(405, function(req, res) --[[...]] end) |
63 |
|
64 | app.exit() -- handle cleanup and then exit, if app hasn't already |
65 |
|