Changeset

2449:c9372cfac3b7

mod_candy: Break out connect path into a function
author Kim Alvefur <zash@zash.se>
date Fri, 20 Jan 2017 01:09:36 +0100
parents 2448:1f7f66272f73
children 2450:36ffe9d11132
files mod_candy/mod_candy.lua
diffstat 1 files changed, 11 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/mod_candy/mod_candy.lua	Thu Jan 19 19:55:39 2017 +0100
+++ b/mod_candy/mod_candy.lua	Fri Jan 20 01:09:36 2017 +0100
@@ -6,24 +6,25 @@
 
 local serve = module:depends"http_files".serve;
 
+local function get_connect_path()
+	if is_module_loaded(module.host, "websocket") then
+		return module:http_url("websocket", "xmpp-websocket"):gsub("^http", "ws");
+	end
+	if not is_module_loaded(module.host, "bosh") then
+		module:depends("bosh");
+	end
+	return module:http_url("bosh", "/http-bind");
+end
+
 module:provides("http", {
 	route = {
 		["GET /prosody.js"] = function(event)
 			event.response.headers.content_type = "text/javascript";
-			local connect_path;
-			if is_module_loaded(module.host, "websocket") then
-				connect_path = module:http_url("websocket", "xmpp-websocket"):gsub("^http", "ws");
-			else
-				if not is_module_loaded(module.host, "bosh") then
-					module:depends("bosh");
-				end
-				connect_path = module:http_url("bosh", "/http-bind");
-			end
 
 			return ("// Generated by Prosody\n"
 				.."var Prosody = %s;\n")
 					:format(json_encode({
-						connect_path = connect_path;
+						connect_path = get_connect_path();
 						version = prosody.version;
 						host = module:get_host();
 						anonymous = module:get_option_string("authentication") == "anonymous";