Software /
code /
prosody-modules
Changeset
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 | 4146:bebc5740fc16 |
children | 4148:34a2e8796cff |
files | mod_conversejs/README.markdown mod_conversejs/mod_conversejs.lua |
diffstat | 2 files changed, 34 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_conversejs/README.markdown Sun Sep 20 15:57:04 2020 +0100 +++ b/mod_conversejs/README.markdown Sun Sep 20 17:06:00 2020 +0200 @@ -91,11 +91,21 @@ `mod_bosh` and/or `mod_websocket` are automatically enabled if available and the respective endpoint is included in the generated options. -Loading resources ------------------ +## Loading resources + +By default the module will load the main script and CSS from +cdn.conversejs.org. For privacy or performance reasons you may want to +load the scripts from somewhere else. -By default the module will load the main script and CSS from cdn.conversejs.org. For privacy or performance -reasons you may want to load the scripts from somewhere else, simply use the conversejs_cdn option: +To use a local distribution or build of Converse.js set +conversejs_resources to the local path of "dist" directory: + +``` {.lua} +conversejs_resources = "/usr/src/conversejs/dist"; +``` + +To use a different web server or CDN simply use the conversejs_cdn +option: ``` {.lua} conversejs_cdn = "https://cdn.example.com"
--- a/mod_conversejs/mod_conversejs.lua Sun Sep 20 15:57:04 2020 +0100 +++ b/mod_conversejs/mod_conversejs.lua Sun Sep 20 17:06:00 2020 +0200 @@ -23,6 +23,25 @@ local version = module:get_option_string("conversejs_version", ""); if version ~= "" then version = "/" .. version end + +local serve_dist = nil; +local resources = module:get_option_path("conversejs_resources"); +if resources then + local serve; + if not pcall(function() + -- Prosody >= trunk / 0.12 + local http_files = require "net.http.files"; + serve = http_files.serve; + end) then + -- Prosody <= 0.11 + serve = module:depends "http_files".serve; + end + local mime_map = module:shared("/*/http_files/mime").types or {css = "text/css"; js = "application/javascript"}; + serve_dist = serve({path = resources; mime_map = mime_map}); + + cdn_url = module:http_url(); +end + local js_url = module:get_option_string("conversejs_script", cdn_url..version.."/dist/converse.min.js"); local css_url = module:get_option_string("conversejs_css", cdn_url..version.."/dist/converse.min.css"); @@ -112,6 +131,7 @@ event.response.headers.content_type = "application/javascript"; return js_template:format(json_encode(converse_options)); end; + ["GET /dist/*"] = serve_dist; } });