aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_http_errors.lua
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/mod_http_errors.lua')
-rw-r--r--plugins/mod_http_errors.lua60
1 files changed, 43 insertions, 17 deletions
diff --git a/plugins/mod_http_errors.lua b/plugins/mod_http_errors.lua
index 13473219..637c894b 100644
--- a/plugins/mod_http_errors.lua
+++ b/plugins/mod_http_errors.lua
@@ -15,6 +15,15 @@ local default_messages = {
"Where did you put it?", "It's behind you.", "Keep looking." };
[500] = { "% Check your error log for more info.";
"Gremlins.", "It broke.", "Don't look at me." };
+ ["/"] = {
+ "A study in simplicity.";
+ "Better catch it!";
+ "Don't just stand there, go after it!";
+ "Well, say something, before it runs too far!";
+ "Welcome to the world of XMPP!";
+ "You can do anything in XMPP!"; -- "The only limit is XML.";
+ "You can do anything with Prosody!"; -- the only limit is memory?
+ };
};
local messages = setmetatable(module:get_option("http_errors_messages", {}), { __index = default_messages });
@@ -26,28 +35,22 @@ local html = [[
<meta charset="utf-8">
<title>{title}</title>
<style>
-body{
- margin-top:14%;
- text-align:center;
- background-color:#F8F8F8;
- font-family:sans-serif;
-}
-h1{
- font-size:xx-large;
-}
-p{
- font-size:x-large;
-}
-p+p {
- font-size:large;
- font-family:courier;
+body{margin-top:14%;text-align:center;background-color:#f8f8f8;font-family:sans-serif}
+h1{font-size:xx-large}
+p{font-size:x-large}
+p.warning>span{font-size:large;background-color:yellow}
+p.extra{font-size:large;font-family:courier}
+@media(prefers-color-scheme:dark){
+body{background-color:#161616;color:#eee}
+p.warning>span{background-color:inherit;color:yellow}
}
</style>
</head>
<body>
<h1>{title}</h1>
<p>{message}</p>
-<p>{extra?}</p>
+{warning&<p class="warning"><span>&#9888; {warning?} &#9888;</span></p>}
+{extra&<p class="extra">{extra?}</p>}
</body>
</html>
]];
@@ -66,9 +69,32 @@ local function get_page(code, extra)
end
end
+-- Main error page handler
module:hook_object_event(server, "http-error", function (event)
if event.response then
event.response.headers.content_type = "text/html; charset=utf-8";
end
- return get_page(event.code, (show_private and event.private_message) or event.message);
+ return get_page(event.code, (show_private and event.private_message) or event.message or (event.error and event.error.text));
end);
+
+-- Way to use the template for other things so to give a consistent appearance
+module:hook("http-message", function (event)
+ if event.response then
+ event.response.headers.content_type = "text/html; charset=utf-8";
+ end
+ return render(html, event);
+end);
+
+-- Something nicer shown instead of 404 at the root path, if nothing else handles this path
+module:hook_object_event(server, "http-error", function (event)
+ local request, response = event.request, event.response;
+ if request and response and request.path == "/" and response.status_code == 404 then
+ response.headers.content_type = "text/html; charset=utf-8";
+ local message = messages["/"];
+ return render(html, {
+ title = "Prosody is running!";
+ message = message[math.random(#message)];
+ });
+ end
+end, 1);
+