2021-05-10 14:13:42 +00:00
|
|
|
cqueues = require "cqueues"
|
|
|
|
socket = require "cqueues.socket"
|
|
|
|
ln = require "ln"
|
|
|
|
|
|
|
|
gemini = require "gemini"
|
|
|
|
|
|
|
|
cq = cqueues.new!
|
|
|
|
|
|
|
|
class ProxyRequestRefusedHandler
|
|
|
|
serve: (ctx, conn) =>
|
|
|
|
conn\write "53 Proxy request refused \r\n"
|
|
|
|
ln.log ctx, {status: 53}
|
|
|
|
|
2021-05-10 20:00:31 +00:00
|
|
|
class FileServer
|
|
|
|
serve: (ctx, conn) =>
|
|
|
|
fname = "./public" .. ctx.path
|
|
|
|
ln.log ctx, :fname
|
|
|
|
fin, err = io.open fname .. "/index.gmi"
|
|
|
|
ln.err err, ctx
|
|
|
|
if err != nil
|
|
|
|
fin, err = io.open fname
|
|
|
|
if err != nil
|
|
|
|
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!
|
2021-05-10 14:13:42 +00:00
|
|
|
\listen socket.listen "127.0.0.1", "58816"
|
2021-05-10 14:41:14 +00:00
|
|
|
\listen socket.listen
|
|
|
|
path: "./var/mipha.sock"
|
|
|
|
unlink: true
|
2021-05-10 14:31:13 +00:00
|
|
|
\attach cq
|
2021-05-10 14:13:42 +00:00
|
|
|
|
|
|
|
assert cq\loop!
|