Mercurial > prosody-hg
annotate plugins/mod_http_errors.lua @ 14224:36aac3343563
net.unbound: Respect use_dnssec=false in case of default TA in lua-event
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Thu, 11 Jun 2026 22:30:27 +0200 |
| parents | 36d361722889 |
| children |
| rev | line source |
|---|---|
|
4711
4ddf3ba0c749
mod_http_errors: Module to handle HTTP errors with a HTML page
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 module:set_global(); |
|
4ddf3ba0c749
mod_http_errors: Module to handle HTTP errors with a HTML page
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 |
|
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
11820
diff
changeset
|
3 local server = require "prosody.net.http.server"; |
|
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
11820
diff
changeset
|
4 local codes = require "prosody.net.http.codes"; |
|
13959
1b95d50cfa18
mod_http_errors: Return errors as JSON if requester prefers that
Matthew Wild <mwild1@gmail.com>
parents:
13393
diff
changeset
|
5 local http_errors = require "prosody.net.http.errors".registry; |
|
1b95d50cfa18
mod_http_errors: Return errors as JSON if requester prefers that
Matthew Wild <mwild1@gmail.com>
parents:
13393
diff
changeset
|
6 local json = require "prosody.util.json"; |
|
1b95d50cfa18
mod_http_errors: Return errors as JSON if requester prefers that
Matthew Wild <mwild1@gmail.com>
parents:
13393
diff
changeset
|
7 local new_short_id = require "prosody.util.id".short; |
|
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
11820
diff
changeset
|
8 local xml_escape = require "prosody.util.stanza".xml_escape; |
|
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
11820
diff
changeset
|
9 local render = require "prosody.util.interpolation".new("%b{}", xml_escape); |
|
4711
4ddf3ba0c749
mod_http_errors: Module to handle HTTP errors with a HTML page
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 |
|
13959
1b95d50cfa18
mod_http_errors: Return errors as JSON if requester prefers that
Matthew Wild <mwild1@gmail.com>
parents:
13393
diff
changeset
|
11 |
|
4711
4ddf3ba0c749
mod_http_errors: Module to handle HTTP errors with a HTML page
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 local show_private = module:get_option_boolean("http_errors_detailed", false); |
|
4737
7b9e2a8c4710
mod_http_errors: Add two new config options, http_errors_always_show (show even for unknown errors) and http_errors_default_message (message for unknown errors)
Matthew Wild <mwild1@gmail.com>
parents:
4711
diff
changeset
|
13 local always_serve = module:get_option_boolean("http_errors_always_show", true); |
|
7b9e2a8c4710
mod_http_errors: Add two new config options, http_errors_always_show (show even for unknown errors) and http_errors_default_message (message for unknown errors)
Matthew Wild <mwild1@gmail.com>
parents:
4711
diff
changeset
|
14 local default_message = { module:get_option_string("http_errors_default_message", "That's all I know.") }; |
|
4711
4ddf3ba0c749
mod_http_errors: Module to handle HTTP errors with a HTML page
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 local default_messages = { |
|
4ddf3ba0c749
mod_http_errors: Module to handle HTTP errors with a HTML page
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 [400] = { "What kind of request do you call that??" }; |
|
4ddf3ba0c749
mod_http_errors: Module to handle HTTP errors with a HTML page
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 [403] = { "You're not allowed to do that." }; |
|
4ddf3ba0c749
mod_http_errors: Module to handle HTTP errors with a HTML page
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 [404] = { "Whatever you were looking for is not here. %"; |
|
4ddf3ba0c749
mod_http_errors: Module to handle HTTP errors with a HTML page
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 "Where did you put it?", "It's behind you.", "Keep looking." }; |
|
4ddf3ba0c749
mod_http_errors: Module to handle HTTP errors with a HTML page
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 [500] = { "% Check your error log for more info."; |
|
4ddf3ba0c749
mod_http_errors: Module to handle HTTP errors with a HTML page
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 "Gremlins.", "It broke.", "Don't look at me." }; |
|
11403
747e8245f180
mod_http_errors: Add some silly variations for the '/' page
Kim Alvefur <zash@zash.se>
parents:
11395
diff
changeset
|
22 ["/"] = { |
|
747e8245f180
mod_http_errors: Add some silly variations for the '/' page
Kim Alvefur <zash@zash.se>
parents:
11395
diff
changeset
|
23 "A study in simplicity."; |
|
747e8245f180
mod_http_errors: Add some silly variations for the '/' page
Kim Alvefur <zash@zash.se>
parents:
11395
diff
changeset
|
24 "Better catch it!"; |
|
747e8245f180
mod_http_errors: Add some silly variations for the '/' page
Kim Alvefur <zash@zash.se>
parents:
11395
diff
changeset
|
25 "Don't just stand there, go after it!"; |
|
747e8245f180
mod_http_errors: Add some silly variations for the '/' page
Kim Alvefur <zash@zash.se>
parents:
11395
diff
changeset
|
26 "Well, say something, before it runs too far!"; |
|
747e8245f180
mod_http_errors: Add some silly variations for the '/' page
Kim Alvefur <zash@zash.se>
parents:
11395
diff
changeset
|
27 "Welcome to the world of XMPP!"; |
|
747e8245f180
mod_http_errors: Add some silly variations for the '/' page
Kim Alvefur <zash@zash.se>
parents:
11395
diff
changeset
|
28 "You can do anything in XMPP!"; -- "The only limit is XML."; |
|
747e8245f180
mod_http_errors: Add some silly variations for the '/' page
Kim Alvefur <zash@zash.se>
parents:
11395
diff
changeset
|
29 "You can do anything with Prosody!"; -- the only limit is memory? |
|
747e8245f180
mod_http_errors: Add some silly variations for the '/' page
Kim Alvefur <zash@zash.se>
parents:
11395
diff
changeset
|
30 }; |
|
4711
4ddf3ba0c749
mod_http_errors: Module to handle HTTP errors with a HTML page
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 }; |
|
4ddf3ba0c749
mod_http_errors: Module to handle HTTP errors with a HTML page
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 |
|
4ddf3ba0c749
mod_http_errors: Module to handle HTTP errors with a HTML page
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 local messages = setmetatable(module:get_option("http_errors_messages", {}), { __index = default_messages }); |
|
4ddf3ba0c749
mod_http_errors: Module to handle HTTP errors with a HTML page
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 |
|
4ddf3ba0c749
mod_http_errors: Module to handle HTTP errors with a HTML page
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 local html = [[ |
|
4ddf3ba0c749
mod_http_errors: Module to handle HTTP errors with a HTML page
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 <!DOCTYPE html> |
|
4ddf3ba0c749
mod_http_errors: Module to handle HTTP errors with a HTML page
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 <html> |
|
4ddf3ba0c749
mod_http_errors: Module to handle HTTP errors with a HTML page
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 <head> |
|
8364
f91ab40a3105
mod_http_errors: Use util.interpolation to render HTML template
Kim Alvefur <zash@zash.se>
parents:
8363
diff
changeset
|
39 <meta charset="utf-8"> |
|
f91ab40a3105
mod_http_errors: Use util.interpolation to render HTML template
Kim Alvefur <zash@zash.se>
parents:
8363
diff
changeset
|
40 <title>{title}</title> |
|
f91ab40a3105
mod_http_errors: Use util.interpolation to render HTML template
Kim Alvefur <zash@zash.se>
parents:
8363
diff
changeset
|
41 <style> |
|
13393
f72ca74de456
mod_http_errors: Simplify CSS via built-in dark mode
Kim Alvefur <zash@zash.se>
parents:
12977
diff
changeset
|
42 :root{color-scheme:light dark} |
|
f72ca74de456
mod_http_errors: Simplify CSS via built-in dark mode
Kim Alvefur <zash@zash.se>
parents:
12977
diff
changeset
|
43 body{margin-top:14%;text-align:center;font-family:sans-serif} |
| 11388 | 44 h1{font-size:xx-large} |
| 45 p{font-size:x-large} | |
| 11395 | 46 p.warning>span{font-size:large;background-color:yellow} |
| 11388 | 47 p.extra{font-size:large;font-family:courier} |
| 48 @media(prefers-color-scheme:dark){ | |
| 11395 | 49 p.warning>span{background-color:inherit;color:yellow} |
| 11154 | 50 } |
|
8364
f91ab40a3105
mod_http_errors: Use util.interpolation to render HTML template
Kim Alvefur <zash@zash.se>
parents:
8363
diff
changeset
|
51 </style> |
|
4711
4ddf3ba0c749
mod_http_errors: Module to handle HTTP errors with a HTML page
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 </head> |
|
4ddf3ba0c749
mod_http_errors: Module to handle HTTP errors with a HTML page
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 <body> |
|
11662
a8798e04b5c8
mod_http_errors: Allow adding icons on error pages
Kim Alvefur <zash@zash.se>
parents:
11404
diff
changeset
|
54 <h1>{icon?{icon_raw!?}} {title}</h1> |
|
8364
f91ab40a3105
mod_http_errors: Use util.interpolation to render HTML template
Kim Alvefur <zash@zash.se>
parents:
8363
diff
changeset
|
55 <p>{message}</p> |
| 11395 | 56 {warning&<p class="warning"><span>⚠ {warning?} ⚠</span></p>} |
|
11155
8d692a8a8f48
mod_http_errors: Remove 'extra' element when empty
Kim Alvefur <zash@zash.se>
parents:
11154
diff
changeset
|
57 {extra&<p class="extra">{extra?}</p>} |
|
4711
4ddf3ba0c749
mod_http_errors: Module to handle HTTP errors with a HTML page
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
58 </body> |
|
7492
9a749cf8c1ba
mod_http_errors: Add a newline after end of HTML
Kim Alvefur <zash@zash.se>
parents:
5776
diff
changeset
|
59 </html> |
|
9a749cf8c1ba
mod_http_errors: Add a newline after end of HTML
Kim Alvefur <zash@zash.se>
parents:
5776
diff
changeset
|
60 ]]; |
|
4711
4ddf3ba0c749
mod_http_errors: Module to handle HTTP errors with a HTML page
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 |
|
4ddf3ba0c749
mod_http_errors: Module to handle HTTP errors with a HTML page
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
62 local function get_page(code, extra) |
|
4ddf3ba0c749
mod_http_errors: Module to handle HTTP errors with a HTML page
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 local message = messages[code]; |
|
4737
7b9e2a8c4710
mod_http_errors: Add two new config options, http_errors_always_show (show even for unknown errors) and http_errors_default_message (message for unknown errors)
Matthew Wild <mwild1@gmail.com>
parents:
4711
diff
changeset
|
64 if always_serve or message then |
|
7b9e2a8c4710
mod_http_errors: Add two new config options, http_errors_always_show (show even for unknown errors) and http_errors_default_message (message for unknown errors)
Matthew Wild <mwild1@gmail.com>
parents:
4711
diff
changeset
|
65 message = message or default_message; |
|
8364
f91ab40a3105
mod_http_errors: Use util.interpolation to render HTML template
Kim Alvefur <zash@zash.se>
parents:
8363
diff
changeset
|
66 return render(html, { |
|
4711
4ddf3ba0c749
mod_http_errors: Module to handle HTTP errors with a HTML page
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
67 title = rawget(codes, code) or ("Code "..tostring(code)); |
|
4ddf3ba0c749
mod_http_errors: Module to handle HTTP errors with a HTML page
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
68 message = message[1]:gsub("%%", function () |
|
4ddf3ba0c749
mod_http_errors: Module to handle HTTP errors with a HTML page
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
69 return message[math.random(2, math.max(#message,2))]; |
|
4ddf3ba0c749
mod_http_errors: Module to handle HTTP errors with a HTML page
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
70 end); |
|
8364
f91ab40a3105
mod_http_errors: Use util.interpolation to render HTML template
Kim Alvefur <zash@zash.se>
parents:
8363
diff
changeset
|
71 extra = extra; |
|
f91ab40a3105
mod_http_errors: Use util.interpolation to render HTML template
Kim Alvefur <zash@zash.se>
parents:
8363
diff
changeset
|
72 }); |
|
4711
4ddf3ba0c749
mod_http_errors: Module to handle HTTP errors with a HTML page
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
73 end |
|
4ddf3ba0c749
mod_http_errors: Module to handle HTTP errors with a HTML page
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
74 end |
|
4ddf3ba0c749
mod_http_errors: Module to handle HTTP errors with a HTML page
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
75 |
|
11404
f7704f987439
mod_http_errors: Add some comments
Kim Alvefur <zash@zash.se>
parents:
11403
diff
changeset
|
76 -- Main error page handler |
|
4711
4ddf3ba0c749
mod_http_errors: Module to handle HTTP errors with a HTML page
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
77 module:hook_object_event(server, "http-error", function (event) |
|
8363
e2460edc2a2f
mod_http_errors: Set Content-Type header to HTML (fixes #1030)
Kim Alvefur <zash@zash.se>
parents:
7492
diff
changeset
|
78 if event.response then |
|
e2460edc2a2f
mod_http_errors: Set Content-Type header to HTML (fixes #1030)
Kim Alvefur <zash@zash.se>
parents:
7492
diff
changeset
|
79 event.response.headers.content_type = "text/html; charset=utf-8"; |
|
e2460edc2a2f
mod_http_errors: Set Content-Type header to HTML (fixes #1030)
Kim Alvefur <zash@zash.se>
parents:
7492
diff
changeset
|
80 end |
|
10574
f70c874b7936
mod_http_errors: Use text from util.errror object if included
Kim Alvefur <zash@zash.se>
parents:
10430
diff
changeset
|
81 return get_page(event.code, (show_private and event.private_message) or event.message or (event.error and event.error.text)); |
|
4711
4ddf3ba0c749
mod_http_errors: Module to handle HTTP errors with a HTML page
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
82 end); |
|
10430
46dd9df2db0c
mod_http_errors: Show a friendly page instead of 404 on top level
Kim Alvefur <zash@zash.se>
parents:
9760
diff
changeset
|
83 |
|
13959
1b95d50cfa18
mod_http_errors: Return errors as JSON if requester prefers that
Matthew Wild <mwild1@gmail.com>
parents:
13393
diff
changeset
|
84 -- Return error object as JSON if that's what requester prefers |
|
1b95d50cfa18
mod_http_errors: Return errors as JSON if requester prefers that
Matthew Wild <mwild1@gmail.com>
parents:
13393
diff
changeset
|
85 module:hook_object_event(server, "http-error", function (event) |
|
13964
36d361722889
mod_http_errors: Fix traceback on missing Accept header
Kim Alvefur <zash@zash.se>
parents:
13959
diff
changeset
|
86 if event.request and (event.request.headers.accept or ""):match("^application/json") then |
|
13959
1b95d50cfa18
mod_http_errors: Return errors as JSON if requester prefers that
Matthew Wild <mwild1@gmail.com>
parents:
13393
diff
changeset
|
87 event.response.headers.content_type = "application/json"; |
|
1b95d50cfa18
mod_http_errors: Return errors as JSON if requester prefers that
Matthew Wild <mwild1@gmail.com>
parents:
13393
diff
changeset
|
88 local error = event.request and event.error; |
|
1b95d50cfa18
mod_http_errors: Return errors as JSON if requester prefers that
Matthew Wild <mwild1@gmail.com>
parents:
13393
diff
changeset
|
89 if not error then |
|
1b95d50cfa18
mod_http_errors: Return errors as JSON if requester prefers that
Matthew Wild <mwild1@gmail.com>
parents:
13393
diff
changeset
|
90 error = http_errors[event.response.status_code]; |
|
1b95d50cfa18
mod_http_errors: Return errors as JSON if requester prefers that
Matthew Wild <mwild1@gmail.com>
parents:
13393
diff
changeset
|
91 end |
|
1b95d50cfa18
mod_http_errors: Return errors as JSON if requester prefers that
Matthew Wild <mwild1@gmail.com>
parents:
13393
diff
changeset
|
92 local extra = error.extra; |
|
1b95d50cfa18
mod_http_errors: Return errors as JSON if requester prefers that
Matthew Wild <mwild1@gmail.com>
parents:
13393
diff
changeset
|
93 return json.encode({ |
|
1b95d50cfa18
mod_http_errors: Return errors as JSON if requester prefers that
Matthew Wild <mwild1@gmail.com>
parents:
13393
diff
changeset
|
94 instance_id = error.instance_id or new_short_id(); |
|
1b95d50cfa18
mod_http_errors: Return errors as JSON if requester prefers that
Matthew Wild <mwild1@gmail.com>
parents:
13393
diff
changeset
|
95 type = error.type; |
|
1b95d50cfa18
mod_http_errors: Return errors as JSON if requester prefers that
Matthew Wild <mwild1@gmail.com>
parents:
13393
diff
changeset
|
96 condition = error.condition; |
|
1b95d50cfa18
mod_http_errors: Return errors as JSON if requester prefers that
Matthew Wild <mwild1@gmail.com>
parents:
13393
diff
changeset
|
97 text = error.text or (show_private and event.private_message) or event.message; |
|
1b95d50cfa18
mod_http_errors: Return errors as JSON if requester prefers that
Matthew Wild <mwild1@gmail.com>
parents:
13393
diff
changeset
|
98 namespace = extra and extra.namespace; |
|
1b95d50cfa18
mod_http_errors: Return errors as JSON if requester prefers that
Matthew Wild <mwild1@gmail.com>
parents:
13393
diff
changeset
|
99 subcondition = extra and extra.condition; |
|
1b95d50cfa18
mod_http_errors: Return errors as JSON if requester prefers that
Matthew Wild <mwild1@gmail.com>
parents:
13393
diff
changeset
|
100 source = error.source or "mod_http_errors"; |
|
1b95d50cfa18
mod_http_errors: Return errors as JSON if requester prefers that
Matthew Wild <mwild1@gmail.com>
parents:
13393
diff
changeset
|
101 }); |
|
1b95d50cfa18
mod_http_errors: Return errors as JSON if requester prefers that
Matthew Wild <mwild1@gmail.com>
parents:
13393
diff
changeset
|
102 end |
|
1b95d50cfa18
mod_http_errors: Return errors as JSON if requester prefers that
Matthew Wild <mwild1@gmail.com>
parents:
13393
diff
changeset
|
103 end, 0.1); |
|
1b95d50cfa18
mod_http_errors: Return errors as JSON if requester prefers that
Matthew Wild <mwild1@gmail.com>
parents:
13393
diff
changeset
|
104 |
|
11404
f7704f987439
mod_http_errors: Add some comments
Kim Alvefur <zash@zash.se>
parents:
11403
diff
changeset
|
105 -- Way to use the template for other things so to give a consistent appearance |
|
11389
29e7ed75ed3f
mod_http_errors: Add way to reuse the error page template
Kim Alvefur <zash@zash.se>
parents:
11388
diff
changeset
|
106 module:hook("http-message", function (event) |
|
29e7ed75ed3f
mod_http_errors: Add way to reuse the error page template
Kim Alvefur <zash@zash.se>
parents:
11388
diff
changeset
|
107 if event.response then |
|
29e7ed75ed3f
mod_http_errors: Add way to reuse the error page template
Kim Alvefur <zash@zash.se>
parents:
11388
diff
changeset
|
108 event.response.headers.content_type = "text/html; charset=utf-8"; |
|
29e7ed75ed3f
mod_http_errors: Add way to reuse the error page template
Kim Alvefur <zash@zash.se>
parents:
11388
diff
changeset
|
109 end |
|
29e7ed75ed3f
mod_http_errors: Add way to reuse the error page template
Kim Alvefur <zash@zash.se>
parents:
11388
diff
changeset
|
110 return render(html, event); |
|
11820
0375ef78ed64
mod_http_errors: Make it easier to override 'http-message' handler
Kim Alvefur <zash@zash.se>
parents:
11664
diff
changeset
|
111 end, -1); |
|
11389
29e7ed75ed3f
mod_http_errors: Add way to reuse the error page template
Kim Alvefur <zash@zash.se>
parents:
11388
diff
changeset
|
112 |
|
11663
04fa947784bc
mod_http_errors: Add a Prosody logo to root page
Kim Alvefur <zash@zash.se>
parents:
11662
diff
changeset
|
113 local icon = [[ |
|
04fa947784bc
mod_http_errors: Add a Prosody logo to root page
Kim Alvefur <zash@zash.se>
parents:
11662
diff
changeset
|
114 <svg xmlns="http://www.w3.org/2000/svg" height="0.7em" viewBox="0 0 480 480" width="0.7em"> |
|
04fa947784bc
mod_http_errors: Add a Prosody logo to root page
Kim Alvefur <zash@zash.se>
parents:
11662
diff
changeset
|
115 <rect fill="#6197df" height="220" rx="60" ry="60" width="220" x="10" y="10"></rect> |
|
04fa947784bc
mod_http_errors: Add a Prosody logo to root page
Kim Alvefur <zash@zash.se>
parents:
11662
diff
changeset
|
116 <rect fill="#f29b00" height="220" rx="60" ry="60" width="220" x="10" y="240"></rect> |
|
04fa947784bc
mod_http_errors: Add a Prosody logo to root page
Kim Alvefur <zash@zash.se>
parents:
11662
diff
changeset
|
117 <rect fill="#f29b00" height="220" rx="60" ry="60" width="220" x="240" y="10"></rect> |
|
04fa947784bc
mod_http_errors: Add a Prosody logo to root page
Kim Alvefur <zash@zash.se>
parents:
11662
diff
changeset
|
118 <rect fill="#6197df" height="220" rx="60" ry="60" width="220" x="240" y="240"></rect> |
|
04fa947784bc
mod_http_errors: Add a Prosody logo to root page
Kim Alvefur <zash@zash.se>
parents:
11662
diff
changeset
|
119 </svg> |
|
04fa947784bc
mod_http_errors: Add a Prosody logo to root page
Kim Alvefur <zash@zash.se>
parents:
11662
diff
changeset
|
120 ]]; |
|
04fa947784bc
mod_http_errors: Add a Prosody logo to root page
Kim Alvefur <zash@zash.se>
parents:
11662
diff
changeset
|
121 |
|
11404
f7704f987439
mod_http_errors: Add some comments
Kim Alvefur <zash@zash.se>
parents:
11403
diff
changeset
|
122 -- Something nicer shown instead of 404 at the root path, if nothing else handles this path |
|
10430
46dd9df2db0c
mod_http_errors: Show a friendly page instead of 404 on top level
Kim Alvefur <zash@zash.se>
parents:
9760
diff
changeset
|
123 module:hook_object_event(server, "http-error", function (event) |
|
46dd9df2db0c
mod_http_errors: Show a friendly page instead of 404 on top level
Kim Alvefur <zash@zash.se>
parents:
9760
diff
changeset
|
124 local request, response = event.request, event.response; |
|
46dd9df2db0c
mod_http_errors: Show a friendly page instead of 404 on top level
Kim Alvefur <zash@zash.se>
parents:
9760
diff
changeset
|
125 if request and response and request.path == "/" and response.status_code == 404 then |
|
11664
d83f8f44caea
mod_http_errors: Set status code 200 from root page
Kim Alvefur <zash@zash.se>
parents:
11663
diff
changeset
|
126 response.status_code = 200; |
|
10430
46dd9df2db0c
mod_http_errors: Show a friendly page instead of 404 on top level
Kim Alvefur <zash@zash.se>
parents:
9760
diff
changeset
|
127 response.headers.content_type = "text/html; charset=utf-8"; |
|
11403
747e8245f180
mod_http_errors: Add some silly variations for the '/' page
Kim Alvefur <zash@zash.se>
parents:
11395
diff
changeset
|
128 local message = messages["/"]; |
|
10430
46dd9df2db0c
mod_http_errors: Show a friendly page instead of 404 on top level
Kim Alvefur <zash@zash.se>
parents:
9760
diff
changeset
|
129 return render(html, { |
|
11663
04fa947784bc
mod_http_errors: Add a Prosody logo to root page
Kim Alvefur <zash@zash.se>
parents:
11662
diff
changeset
|
130 icon_raw = icon, |
|
10430
46dd9df2db0c
mod_http_errors: Show a friendly page instead of 404 on top level
Kim Alvefur <zash@zash.se>
parents:
9760
diff
changeset
|
131 title = "Prosody is running!"; |
|
11403
747e8245f180
mod_http_errors: Add some silly variations for the '/' page
Kim Alvefur <zash@zash.se>
parents:
11395
diff
changeset
|
132 message = message[math.random(#message)]; |
|
10430
46dd9df2db0c
mod_http_errors: Show a friendly page instead of 404 on top level
Kim Alvefur <zash@zash.se>
parents:
9760
diff
changeset
|
133 }); |
|
46dd9df2db0c
mod_http_errors: Show a friendly page instead of 404 on top level
Kim Alvefur <zash@zash.se>
parents:
9760
diff
changeset
|
134 end |
|
46dd9df2db0c
mod_http_errors: Show a friendly page instead of 404 on top level
Kim Alvefur <zash@zash.se>
parents:
9760
diff
changeset
|
135 end, 1); |
|
46dd9df2db0c
mod_http_errors: Show a friendly page instead of 404 on top level
Kim Alvefur <zash@zash.se>
parents:
9760
diff
changeset
|
136 |
