Software / code / prosody-modules
Annotate
mod_http_libjs/mod_http_libjs.lua @ 6244:c71d8bc77c95
mod_rest: Skip unpacking error object when missing (thanks Martin)
Not every "http-error" event includes a .error field, so it may attempt
to unpack `nil`.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Tue, 22 Apr 2025 09:40:20 +0200 |
| parent | 6224:0bd1804baae7 |
| rev | line source |
|---|---|
|
6224
0bd1804baae7
mod_http_libjs: Remove compatibility with 0.11
Link Mauve <linkmauve@linkmauve.fr>
parents:
4976
diff
changeset
|
1 local http_files = require "net.http.files"; |
|
0bd1804baae7
mod_http_libjs: Remove compatibility with 0.11
Link Mauve <linkmauve@linkmauve.fr>
parents:
4976
diff
changeset
|
2 |
|
4087
88a469b285f5
mod_http_libjs: New module to serve common CSS/Javascript libraries
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 local mime_map = module:shared("/*/http_files/mime").types or { |
|
88a469b285f5
mod_http_libjs: New module to serve common CSS/Javascript libraries
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 css = "text/css", |
|
88a469b285f5
mod_http_libjs: New module to serve common CSS/Javascript libraries
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 js = "application/javascript", |
|
88a469b285f5
mod_http_libjs: New module to serve common CSS/Javascript libraries
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 }; |
|
88a469b285f5
mod_http_libjs: New module to serve common CSS/Javascript libraries
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 |
|
88a469b285f5
mod_http_libjs: New module to serve common CSS/Javascript libraries
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 local libjs_path = module:get_option_string("libjs_path", "/usr/share/javascript"); |
|
88a469b285f5
mod_http_libjs: New module to serve common CSS/Javascript libraries
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 |
|
4604
f0efbb0b0b5b
mod_http_libjs: Check that the path to serve exists
Kim Alvefur <zash@zash.se>
parents:
4095
diff
changeset
|
10 do -- sanity check |
|
f0efbb0b0b5b
mod_http_libjs: Check that the path to serve exists
Kim Alvefur <zash@zash.se>
parents:
4095
diff
changeset
|
11 local lfs = require "lfs"; |
|
f0efbb0b0b5b
mod_http_libjs: Check that the path to serve exists
Kim Alvefur <zash@zash.se>
parents:
4095
diff
changeset
|
12 |
|
f0efbb0b0b5b
mod_http_libjs: Check that the path to serve exists
Kim Alvefur <zash@zash.se>
parents:
4095
diff
changeset
|
13 local exists, err = lfs.attributes(libjs_path, "mode"); |
|
f0efbb0b0b5b
mod_http_libjs: Check that the path to serve exists
Kim Alvefur <zash@zash.se>
parents:
4095
diff
changeset
|
14 if exists ~= "directory" then |
|
f0efbb0b0b5b
mod_http_libjs: Check that the path to serve exists
Kim Alvefur <zash@zash.se>
parents:
4095
diff
changeset
|
15 module:log("error", "Problem with 'libjs_path': %s", err or "not a directory"); |
|
f0efbb0b0b5b
mod_http_libjs: Check that the path to serve exists
Kim Alvefur <zash@zash.se>
parents:
4095
diff
changeset
|
16 end |
|
f0efbb0b0b5b
mod_http_libjs: Check that the path to serve exists
Kim Alvefur <zash@zash.se>
parents:
4095
diff
changeset
|
17 end |
|
f0efbb0b0b5b
mod_http_libjs: Check that the path to serve exists
Kim Alvefur <zash@zash.se>
parents:
4095
diff
changeset
|
18 |
|
4087
88a469b285f5
mod_http_libjs: New module to serve common CSS/Javascript libraries
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 module:provides("http", { |
|
88a469b285f5
mod_http_libjs: New module to serve common CSS/Javascript libraries
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 default_path = "/share"; |
|
88a469b285f5
mod_http_libjs: New module to serve common CSS/Javascript libraries
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 route = { |
|
6224
0bd1804baae7
mod_http_libjs: Remove compatibility with 0.11
Link Mauve <linkmauve@linkmauve.fr>
parents:
4976
diff
changeset
|
22 ["GET /*"] = http_files.serve({ path = libjs_path, mime_map = mime_map }); |
|
4087
88a469b285f5
mod_http_libjs: New module to serve common CSS/Javascript libraries
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 } |
|
88a469b285f5
mod_http_libjs: New module to serve common CSS/Javascript libraries
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 }); |