changeset 3312:e714be00aaad

mod_conversejs: Factor JavaScript part out of HTML This will allow serving only the JS snippet in the future.
author Kim Alvefur <zash@zash.se>
date Mon, 10 Sep 2018 15:04:03 +0200 (2018-09-10)
parents 5b3347056f07
children d6b922191aeb
files mod_conversejs/mod_conversejs.lua
diffstat 1 files changed, 5 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mod_conversejs/mod_conversejs.lua	Mon Sep 10 14:49:49 2018 +0200
+++ b/mod_conversejs/mod_conversejs.lua	Mon Sep 10 15:04:03 2018 +0200
@@ -9,7 +9,7 @@
 	module:depends("websocket");
 end);
 
-local template = [[
+local html_template = [[
 <!DOCTYPE html>
 <html>
 <head>
@@ -37,11 +37,13 @@
 </dl>
 <p><a href="https://xmpp.org/software/clients.html">More clients...</a></p>
 </noscript>
-<script>converse.initialize(%s);</script>
+<script>%s</script>
 </body>
 </html>
 ]]
 
+js_template = "converse.initialize(%s);";
+
 local more_options = module:get_option("conversejs_options");
 
 module:provides("http", {
@@ -66,7 +68,7 @@
 			end
 
 			event.response.headers.content_type = "text/html";
-			return template:format(json_encode(converse_options));
+			return html_template:format(js_template:format(json_encode(converse_options)));
 		end;
 	}
 });