# HG changeset patch # User Kim Alvefur # Date 1484870976 -3600 # Node ID c9372cfac3b771129afc26191d5e7b64f76a26d4 # Parent 1f7f66272f7394af9ec4e2043675bd60976424ec mod_candy: Break out connect path into a function diff -r 1f7f66272f73 -r c9372cfac3b7 mod_candy/mod_candy.lua --- 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";