Annotate

mod_http_libjs/mod_http_libjs.lua @ 6224:0bd1804baae7

mod_http_libjs: Remove compatibility with 0.11
author Link Mauve <linkmauve@linkmauve.fr>
date Wed, 09 Apr 2025 19:04:49 +0200
parent 4976:75b6e5df65f9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 });