Index

joshstock.in / 415f7bc

Source for serving and static templating/compiling of https://joshstock.in.

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
8825 Aug 2020 16:09c8cb357Begin base git history rewriteJosh Stockin1640G

Blob @ joshstock.in / git-history / app.lua

text/plain2547 bytesdownload raw
1profess = {}
2
3if not ngx then
4 print("FATAL ERROR: no ngx module. Are you using ngx_lua (OpenResty)?")
5 return 1
6end
7
8profess.version_major = 0
9profess.version_minor = 1
10profess.version_patch = 0
11profess.version_string = string.format("profess/%d.%d.%d", profess.version_major, profess.version_minor, profess.version_patch)
12
13ngx.header.Content_Type = "text/html"
14ngx.header.Server = profess.version_string
15ngx.say("<html><head><title>aaaaa</title></head><body>")
16ngx.say("<h1>hello from " .. profess.version_string .. "</h1>")
17ngx.say("<p>Running Lua version " .. _VERSION .." (LuaJIT)</p>")
18ngx.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>")
19ngx.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>")
20ngx.say("<p>nginx worker " .. tostring(ngx.worker.pid()) .. "</p>")
21for i=0,1000 do ngx.say("a") end
22ngx.say("</body></html>")
23ngx.exit(ngx.HTTP_OK)
24
25local profess = require("profess")
26local app = profess.app()
27
28app.authorize("")
29
30app.rewrite("^/(.*)/$", "/$1") -- rewrite trailing slashes
31
32app.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
53end)
54
55app.route("/", function(req, res) --[[...]] end) -- all of these
56app.route("/", "GET", function(req, res) --[[...]] end) -- calls are the
57app.get("/", function(req, res) --[[...]] end) -- same
58
59app.code_route("/api", 404, function(req, res) --[[...]] end)
60app.code_route("/api", 405, function(req, res) --[[...]] end)
61app.code_default(404, function(req, res) --[[...]] end)
62app.code_default(405, function(req, res) --[[...]] end)
63
64app.exit() -- handle cleanup and then exit, if app hasn't already
65