make the gemini server more generic

Signed-off-by: Christine Dodrill <me@christine.website>
This commit is contained in:
Cadey Ratio 2021-05-10 14:13:42 +00:00
parent cd8a9a1168
commit d5dfe68ad6
3 changed files with 28 additions and 33 deletions

View File

@ -1,17 +1,5 @@
cqueues = require "cqueues"
socket = require "cqueues.socket"
ln = require "ln"
url = require "net.url" url = require "net.url"
srv = socket.listen "127.0.0.1", "58816"
cq = cqueues.new!
class ProxyRequestRefusedHandler
run: (ctx, conn) =>
conn\write "53 Proxy request refused \r\n"
ln.log ctx, {status: 53}
class Server class Server
new: (cq, hdlr) => new: (cq, hdlr) =>
@cq = cq @cq = cq
@ -30,26 +18,9 @@ class Server
host: u.host host: u.host
path: u.path path: u.path
query: u.query query: u.query
@hdlr\run ctx, conn @hdlr\serve ctx, conn
\close! \close!
-- cq\wrap -> {
-- for conn in srv\clients! :Server
-- cq\wrap -> }
-- with conn
-- _, ip = \peername!
-- request = \read "*l"
-- u = url.parse request
-- ctx =
-- :ip
-- host: u.host
-- path: u.path
-- query: u.query
-- ln.log ctx
-- \write "53 Proxy request refused\r\n"
-- \close!
with Server cq, ProxyRequestRefusedHandler!
\listen srv
assert cq\loop!

20
mipha.moon Normal file
View File

@ -0,0 +1,20 @@
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}
with gemini.Server cq, ProxyRequestRefusedHandler!
\listen socket.listen "127.0.0.1", "58816"
\listen socket.listen
path: "./var/mipha.sock"
unlink: true
assert cq\loop!

View File

@ -10,4 +10,8 @@ in pkgs.mkShell {
busted busted
moonscript moonscript
]; ];
shellHook = ''
LUA_PATH="$LUA_PATH;./?.lua;./?/init.lua"
'';
} }