2 local httpserver = require "net.httpserver";
5 local t_concat = table.concat;
7 local http_base = "www_files";
9 local response_404 = { status = "404 Not Found", body = "<h1>Page Not Found</h1>Sorry, we couldn't find what you were looking for :(" };
11 local http_path = { http_base };
12 local function handle_request(method, body, request)
13 local path = request.url.path:gsub("%.%.%/", ""):gsub("^/[^/]+", "");
15 local f, err = open(t_concat(http_path), "r");
16 if not f then return response_404; end
17 local data = f:read("*a");
22 httpserver.new{ port = 5280, base = "files", handler = handle_request, ssl = false}