Comparison

mod_conversejs/mod_conversejs.lua @ 2657:6f5c99c9f6cc

mod_conversejs: Simple demo module for serving converse.js from internal http server
author Kim Alvefur <zash@zash.se>
date Thu, 30 Mar 2017 23:41:09 +0200
child 2658:b0f4014cb5b4
comparison
equal deleted inserted replaced
2656:83fb61fa476e 2657:6f5c99c9f6cc
1 -- mod_conversejs
2 -- Copyright (C) 2017 Kim Alvefur
3
4 local json_encode = require"util.json".encode;
5
6 module:depends"bosh";
7
8 local has_ws = pcall(function ()
9 module:depends("websocket");
10 end);
11
12 local serve = module:depends"http_files".serve;
13
14 local template = [[
15 <!DOCTYPE html>
16 <meta charset="utf-8">
17 <link rel="stylesheet" type="text/css" media="screen" href="https://cdn.conversejs.org/css/converse.min.css">
18 <script src="https://cdn.conversejs.org/dist/converse.min.js"></script>
19 <script>converse.initialize(%s);</script>
20 ]]
21
22 module:provides("http", {
23 route = {
24 GET = function (event)
25 event.response.headers.content_type = "text/html";
26 return template:format(json_encode({
27 -- debug = true,
28 bosh_service_url = module:http_url("bosh","/http-bind");
29 websocket_url = has_ws and module:http_url("websocket","xmpp-websocket"):gsub("^http", "ws") or nil;
30 authentication = module:get_option_string("authentication") == "anonymous" and "anonymous" or "login";
31 }));
32 end;
33 }
34 });
35