Software /
code /
prosody
Comparison
plugins/mod_http.lua @ 4702:5a85e541de1a
mod_http: Switch to single option for specifying HTTP app bases, http_paths. Keys are app/module names, values are base paths.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 26 Apr 2012 06:41:11 +0100 |
parent | 4696:4700e318add1 |
child | 4717:3c0321e3fa76 |
comparison
equal
deleted
inserted
replaced
4701:3ce9e1ca9c15 | 4702:5a85e541de1a |
---|---|
27 end | 27 end |
28 path = normalize_path(path); | 28 path = normalize_path(path); |
29 return method:upper().." "..host..app_path..path; | 29 return method:upper().." "..host..app_path..path; |
30 end | 30 end |
31 | 31 |
32 local function get_base_path(host_module, app_name, default_app_path) | |
33 return host_module:get_option("http_paths", {})[app_name] -- Host | |
34 or module:get_option("http_paths", {})[app_name] -- Global | |
35 or default_app_path; -- Default | |
36 end | |
37 | |
32 function module.add_host(module) | 38 function module.add_host(module) |
33 local host = module.host; | 39 local host = module.host; |
34 local apps = {}; | 40 local apps = {}; |
35 module.environment.apps = apps; | 41 module.environment.apps = apps; |
36 local function http_app_added(event) | 42 local function http_app_added(event) |
37 local app_name = event.item.name; | 43 local app_name = event.item.name; |
38 local default_app_path = event.item.default_path or "/"..app_name; | 44 local default_app_path = event.item.default_path or "/"..app_name; |
39 local app_path = normalize_path(module:get_option_string(app_name.."_http_path", default_app_path)); | 45 local app_path = normalize_path(get_base_path(module, app_name, default_app_path)); |
40 if not app_name then | 46 if not app_name then |
41 -- TODO: Link to docs | 47 -- TODO: Link to docs |
42 module:log("error", "HTTP app has no 'name', add one or use module:provides('http', app)"); | 48 module:log("error", "HTTP app has no 'name', add one or use module:provides('http', app)"); |
43 return; | 49 return; |
44 end | 50 end |