2 -- Copyright (C) 2008-2009 Matthew Wild
3 -- Copyright (C) 2008-2009 Waqas Hussain
5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information.
10 local httpserver = require "net.httpserver";
13 local t_concat = table.concat;
15 local http_base = "www_files";
17 local response_404 = { status = "404 Not Found", body = "<h1>Page Not Found</h1>Sorry, we couldn't find what you were looking for :(" };
19 local http_path = { http_base };
20 local function handle_request(method, body, request)
21 local path = request.url.path:gsub("%.%.%/", ""):gsub("^/[^/]+", "");
23 local f, err = open(t_concat(http_path), "r");
24 if not f then return response_404; end
25 local data = f:read("*a");
30 local ports = config.get(module.host, "core", "http_ports") or { 5280 };
31 httpserver.new_from_config(ports, "files", handle_request);