mipha/mipha.moon

40 lines
837 B
Plaintext
Raw Normal View History

cqueues = require "cqueues"
ln = require "ln"
socket = require "cqueues.socket"
gemini = require "gemini"
cq = cqueues.new!
class ProxyRequestRefusedHandler
serve: (ctx, conn) =>
conn\write "53 Proxy request refused \r\n"
ln.log ctx, {status: 53}
class FileServer
serve: (ctx, conn) =>
fname = "./public" .. ctx.path
ln.log ctx, :fname
fin, err = io.open fname .. "/index.gmi"
if err != nil
fin, err = io.open fname
if err != nil
ln.err err, ctx
conn\write "51 not found: " .. ctx.path .. "\r\n"
conn\write "20 text/gemini\r\n"
for line in fin\lines!
conn\write line
conn\flush!
with gemini.Server FileServer!
\listen socket.listen "127.0.0.1", "58816"
\listen socket.listen
path: "./var/mipha.sock"
unlink: true
\attach cq
assert cq\loop!