view mod_http_libjs/mod_http_libjs.lua @ 4604:f0efbb0b0b5b

mod_http_libjs: Check that the path to serve exists
author Kim Alvefur <zash@zash.se>
date Tue, 29 Jun 2021 12:41:43 +0200
parents de2390d6bbe4
children 75b6e5df65f9
line wrap: on
line source

local mime_map = module:shared("/*/http_files/mime").types or {
	css = "text/css",
	js = "application/javascript",
};

local serve;
if not pcall(function ()
	local http_files = require "net.http.files";
	serve = http_files.serve;
end) then
	serve = module:depends"http_files".serve;
end

local libjs_path = module:get_option_string("libjs_path", "/usr/share/javascript");

do -- sanity check
	local lfs = require "lfs";

	local exists, err = lfs.attributes(libjs_path, "mode");
	if exists ~= "directory" then
		module:log("error", "Problem with 'libjs_path': %s", err or "not a directory");
	end
end

module:provides("http", {
		default_path = "/share";
		route = {
			["GET /*"] = serve({ path = libjs_path, mime_map = mime_map });
		}
	});