Software /
code /
prosody
Comparison
plugins/mod_http_errors.lua @ 11200:bf8f2da84007
Merge 0.11->trunk
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 05 Nov 2020 22:31:25 +0100 |
parent | 11155:8d692a8a8f48 |
child | 11388:60a61c509d87 |
comparison
equal
deleted
inserted
replaced
11199:6c7c50a4de32 | 11200:bf8f2da84007 |
---|---|
24 <html> | 24 <html> |
25 <head> | 25 <head> |
26 <meta charset="utf-8"> | 26 <meta charset="utf-8"> |
27 <title>{title}</title> | 27 <title>{title}</title> |
28 <style> | 28 <style> |
29 body{ | 29 body { |
30 margin-top:14%; | 30 margin-top : 14%; |
31 text-align:center; | 31 text-align : center; |
32 background-color:#F8F8F8; | 32 background-color : #F8F8F8; |
33 font-family:sans-serif; | 33 font-family : sans-serif |
34 } | 34 } |
35 h1{ | 35 |
36 font-size:xx-large; | 36 h1 { |
37 font-size : xx-large | |
37 } | 38 } |
38 p{ | 39 |
39 font-size:x-large; | 40 p { |
41 font-size : x-large | |
40 } | 42 } |
41 p+p { | 43 |
42 font-size:large; | 44 p.extra { |
43 font-family:courier; | 45 font-size : large; |
46 font-family : courier | |
47 } | |
48 | |
49 @media(prefers-color-scheme: dark) { | |
50 body { | |
51 background-color: #161616; | |
52 color: #eee | |
53 } | |
44 } | 54 } |
45 </style> | 55 </style> |
46 </head> | 56 </head> |
47 <body> | 57 <body> |
48 <h1>{title}</h1> | 58 <h1>{title}</h1> |
49 <p>{message}</p> | 59 <p>{message}</p> |
50 <p>{extra?}</p> | 60 {extra&<p class="extra">{extra?}</p>} |
51 </body> | 61 </body> |
52 </html> | 62 </html> |
53 ]]; | 63 ]]; |
54 | 64 |
55 local function get_page(code, extra) | 65 local function get_page(code, extra) |
68 | 78 |
69 module:hook_object_event(server, "http-error", function (event) | 79 module:hook_object_event(server, "http-error", function (event) |
70 if event.response then | 80 if event.response then |
71 event.response.headers.content_type = "text/html; charset=utf-8"; | 81 event.response.headers.content_type = "text/html; charset=utf-8"; |
72 end | 82 end |
73 return get_page(event.code, (show_private and event.private_message) or event.message); | 83 return get_page(event.code, (show_private and event.private_message) or event.message or (event.error and event.error.text)); |
74 end); | 84 end); |
85 | |
86 module:hook_object_event(server, "http-error", function (event) | |
87 local request, response = event.request, event.response; | |
88 if request and response and request.path == "/" and response.status_code == 404 then | |
89 response.headers.content_type = "text/html; charset=utf-8"; | |
90 return render(html, { | |
91 title = "Prosody is running!"; | |
92 message = "Welcome to the XMPP world!"; | |
93 }); | |
94 end | |
95 end, 1); | |
96 |