Software /
code /
prosody
Comparison
plugins/mod_http_files.lua @ 5268:69964d1cbe66
mod_http_files: Allow passing a string to serve()
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 23 Dec 2012 11:17:44 +0100 |
parent | 5265:cc2aed452a62 |
child | 5269:7bc52402966d |
comparison
equal
deleted
inserted
replaced
5267:a2080e5c4eda | 5268:69964d1cbe66 |
---|---|
49 end | 49 end |
50 | 50 |
51 local cache = setmetatable({}, { __mode = "kv" }); -- Let the garbage collector have it if it wants to. | 51 local cache = setmetatable({}, { __mode = "kv" }); -- Let the garbage collector have it if it wants to. |
52 | 52 |
53 function serve(opts) | 53 function serve(opts) |
54 if type(opts) ~= "table" then -- assume path string | |
55 opts = { path = opts }; | |
56 end | |
54 local base_path = opts.path; | 57 local base_path = opts.path; |
55 local dir_indices = opts.index_files or dir_indices; | 58 local dir_indices = opts.index_files or dir_indices; |
56 local directory_index = opts.directory_index; | 59 local directory_index = opts.directory_index; |
57 local function serve_file(event, path) | 60 local function serve_file(event, path) |
58 local request, response = event.request, event.response; | 61 local request, response = event.request, event.response; |
126 return serve_file; | 129 return serve_file; |
127 end | 130 end |
128 | 131 |
129 function wrap_route(routes) | 132 function wrap_route(routes) |
130 for route,handler in pairs(routes) do | 133 for route,handler in pairs(routes) do |
131 if type(handler) == "table" and handler.path then | 134 if type(handler) ~= "function" then |
132 routes[route] = serve(handler); | 135 routes[route] = serve(handler); |
133 end | 136 end |
134 end | 137 end |
135 return routes; | 138 return routes; |
136 end | 139 end |