From d5dfe68ad6c8ce77b47c302f2f3ce94baba8248a Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Mon, 10 May 2021 14:13:42 +0000 Subject: [PATCH] make the gemini server more generic Signed-off-by: Christine Dodrill --- gemini.moon | 37 ++++--------------------------------- mipha.moon | 20 ++++++++++++++++++++ shell.nix | 4 ++++ 3 files changed, 28 insertions(+), 33 deletions(-) create mode 100644 mipha.moon diff --git a/gemini.moon b/gemini.moon index f91f03d..6d560aa 100644 --- a/gemini.moon +++ b/gemini.moon @@ -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 +} diff --git a/mipha.moon b/mipha.moon new file mode 100644 index 0000000..1e24620 --- /dev/null +++ b/mipha.moon @@ -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! diff --git a/shell.nix b/shell.nix index d46943b..87099eb 100644 --- a/shell.nix +++ b/shell.nix @@ -10,4 +10,8 @@ in pkgs.mkShell { busted moonscript ]; + + shellHook = '' + LUA_PATH="$LUA_PATH;./?.lua;./?/init.lua" + ''; }