Mercurial > prosody-modules
comparison mod_conversejs/mod_conversejs.lua @ 4147:3a06dea21ea1
mod_conversejs: Enable serving resources from built-in http server
This enables using release archives or locally built Converse.js
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 20 Sep 2020 17:06:00 +0200 |
parents | 36b6e3e3f9e2 |
children | 4ee2a90d3818 |
comparison
equal
deleted
inserted
replaced
4146:bebc5740fc16 | 4147:3a06dea21ea1 |
---|---|
21 | 21 |
22 local cdn_url = module:get_option_string("conversejs_cdn", "https://cdn.conversejs.org"); | 22 local cdn_url = module:get_option_string("conversejs_cdn", "https://cdn.conversejs.org"); |
23 | 23 |
24 local version = module:get_option_string("conversejs_version", ""); | 24 local version = module:get_option_string("conversejs_version", ""); |
25 if version ~= "" then version = "/" .. version end | 25 if version ~= "" then version = "/" .. version end |
26 | |
27 local serve_dist = nil; | |
28 local resources = module:get_option_path("conversejs_resources"); | |
29 if resources then | |
30 local serve; | |
31 if not pcall(function() | |
32 -- Prosody >= trunk / 0.12 | |
33 local http_files = require "net.http.files"; | |
34 serve = http_files.serve; | |
35 end) then | |
36 -- Prosody <= 0.11 | |
37 serve = module:depends "http_files".serve; | |
38 end | |
39 local mime_map = module:shared("/*/http_files/mime").types or {css = "text/css"; js = "application/javascript"}; | |
40 serve_dist = serve({path = resources; mime_map = mime_map}); | |
41 | |
42 cdn_url = module:http_url(); | |
43 end | |
44 | |
26 local js_url = module:get_option_string("conversejs_script", cdn_url..version.."/dist/converse.min.js"); | 45 local js_url = module:get_option_string("conversejs_script", cdn_url..version.."/dist/converse.min.js"); |
27 local css_url = module:get_option_string("conversejs_css", cdn_url..version.."/dist/converse.min.css"); | 46 local css_url = module:get_option_string("conversejs_css", cdn_url..version.."/dist/converse.min.css"); |
28 | 47 |
29 local html_template; | 48 local html_template; |
30 | 49 |
110 local converse_options = get_converse_options(); | 129 local converse_options = get_converse_options(); |
111 | 130 |
112 event.response.headers.content_type = "application/javascript"; | 131 event.response.headers.content_type = "application/javascript"; |
113 return js_template:format(json_encode(converse_options)); | 132 return js_template:format(json_encode(converse_options)); |
114 end; | 133 end; |
134 ["GET /dist/*"] = serve_dist; | |
115 } | 135 } |
116 }); | 136 }); |
117 | 137 |