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"
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
new: (cq, hdlr) =>
@cq = cq
@ -30,26 +18,9 @@ class Server
host: u.host
path: u.path
query: u.query
@hdlr\run ctx, conn
@hdlr\serve ctx, conn
\close!
-- cq\wrap ->
-- for conn in srv\clients!
-- 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!
{
:Server
}

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
moonscript
];
shellHook = ''
LUA_PATH="$LUA_PATH;./?.lua;./?/init.lua"
'';
}