diff options
| author | 2016-03-05 09:52:54 -0500 | |
|---|---|---|
| committer | 2016-03-05 09:52:54 -0500 | |
| commit | 50fc05a49fcc6b689271ecff2dfae209bb4bfd47 (patch) | |
| tree | 9bce43cfb23e17399376f45ee18a417b0dee5eef /plugins/weblit/static.lua | |
| parent | f7b8e47a17efd84963e685c39840ff111787d929 (diff) | |
| parent | 23eaaa9244ffa216e0b8365916d9cf3af785279b (diff) | |
Merge branch 'master' of https://github.com/mamedev/mame.git
Diffstat (limited to 'plugins/weblit/static.lua')
| -rw-r--r-- | plugins/weblit/static.lua | 62 |
1 files changed, 0 insertions, 62 deletions
diff --git a/plugins/weblit/static.lua b/plugins/weblit/static.lua deleted file mode 100644 index b34ea638fa1..00000000000 --- a/plugins/weblit/static.lua +++ /dev/null @@ -1,62 +0,0 @@ - -local getType = require("mime").getType -local jsonStringify = require('json').stringify - -local makeChroot = require('coro-fs').chroot - -return function (rootPath) - - local fs = makeChroot(rootPath) - - return function (req, res, go) - if req.method ~= "GET" then return go() end - local path = (req.params and req.params.path) or req.path - path = path:match("^[^?#]*") - if path:byte(1) == 47 then - path = path:sub(2) - end - local stat = fs.stat(path) - if not stat then return go() end - - local function renderFile() - local body = assert(fs.readFile(path)) - res.code = 200 - res.headers["Content-Type"] = getType(path) - res.body = body - return - end - - local function renderDirectory() - if req.path:byte(-1) ~= 47 then - res.code = 301 - res.headers.Location = req.path .. '/' - return - end - local files = {} - for entry in fs.scandir(path) do - if entry.name == "index.html" and entry.type == "file" then - path = (#path > 0 and path .. "/" or "") .. "index.html" - return renderFile() - end - files[#files + 1] = entry - entry.url = "http://" .. req.headers.host .. req.path .. entry.name - end - local body = jsonStringify(files) .. "\n" - res.code = 200 - res.headers["Content-Type"] = "application/json" - res.body = body - return - end - - if stat.type == "directory" then - return renderDirectory() - elseif stat.type == "file" then - if req.path:byte(-1) == 47 then - res.code = 301 - res.headers.Location = req.path:match("^(.*[^/])/+$") - return - end - return renderFile() - end - end -end |
