-- if you have a working luafilesystems
-- require "lfs"
-- attr = lfs.attributes(lighty.env["physical.path"])
-- if (attr) then

-- fallback solution via io.open
fname = lighty.env["physical.path"]
print ("checking for " .. fname )
f = io.open(fname, "r")
if (f) then
  f:close()
  -- io.open returns nil + a error-msg on the stack
  -- comment darix: this pop seems unneeded
  --  pop(1)

  -- file exists, send it
  -- we might also check for dir, file, socket, ...
  --
  lighty.content = { { filename = fname } }

  return 200
end
-- path doesn't exist ... rewrite it
--
fname = lighty.env["physical.path"] .. ".html"
print ("checking for " .. fname )
f = io.open(fname, "r")
if (f) then
  f:close()
  -- io.open returns nil + a error-msg on the stack
  -- comment darix: this pop seems unneeded
  --  pop(1)

  -- file exists, send it
  -- we might also check for dir, file, socket, ...
  --
  lighty.content = { { filename = fname } }

  return 200
end

lighty.env["uri.path"] = "/dispatch.fcgi"
lighty.env["physical.rel-path"] = lighty.env["uri.path"]
lighty.env["physical.path"] = lighty.env["physical.doc-root"] .. lighty.env["physical.rel-path"]

--return lighty.RESTART_REQUEST

