Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

42 lines (35 sloc) 1.046 kb
local mime = require('mime')
local http = require('http')
local url = require('url')
local fs = require('fs')
local path = require('path')
local Response = require('http').Response
function Response:destroy()
if self.socket then
return self.socket.destroy()
end
end
function Response:sendfile(status, filepath)
fs.stat(filepath, function(err, st)
self:writeHead(status, {
["Content-Type"] = mime.getType(filepath),
["Content-Length"] = st.size
})
fs.createReadStream(filepath):pipe(self)
end)
end
local root = '.'
http.createServer(function(req, res)
req.uri = url.parse(req.url)
local filepath = path.normalize(root .. req.uri.pathname)
fs.stat(filepath, function (err, stat)
if err then
if err.code == "ENOENT" or not stat.is_file then
return res:sendfile(404, root .. '/404.html')
end
return res:sendfile(500, root .. '/500.html')
end
return res:sendfile(200, filepath)
end)
end):listen(7373)
print("Lunatic listening at http://localhost:" .. "7373/")
Jump to Line
Something went wrong with that request. Please try again.