From 873fe3f7d94392af687d925c97fa7b61dda9539c Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Mon, 10 May 2021 20:00:31 +0000 Subject: [PATCH] fileserver! Signed-off-by: Christine Dodrill --- gemini.moon | 6 ++---- mipha.moon | 20 +++++++++++++++++++- public/foo.gmi | 1 + public/index.gmi | 1 + 4 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 public/foo.gmi create mode 100644 public/index.gmi diff --git a/gemini.moon b/gemini.moon index 73d0b76..a38748e 100644 --- a/gemini.moon +++ b/gemini.moon @@ -16,15 +16,13 @@ class Server @cq\wrap -> with conn _, ip = \peername! - pid, uid, gid = \peerpid!, \peereid! request = \read "*l" \shutdown "r" u = url.parse request + if u.path == "" + u.path = "/" ctx = :ip - :pid - :uid - :gid host: u.host path: u.path query: u.query diff --git a/mipha.moon b/mipha.moon index 7186c0e..0f6b303 100644 --- a/mipha.moon +++ b/mipha.moon @@ -11,7 +11,25 @@ class ProxyRequestRefusedHandler conn\write "53 Proxy request refused \r\n" ln.log ctx, {status: 53} -with gemini.Server ProxyRequestRefusedHandler! +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! \listen socket.listen "127.0.0.1", "58816" \listen socket.listen path: "./var/mipha.sock" diff --git a/public/foo.gmi b/public/foo.gmi new file mode 100644 index 0000000..c2a8392 --- /dev/null +++ b/public/foo.gmi @@ -0,0 +1 @@ +# foo diff --git a/public/index.gmi b/public/index.gmi new file mode 100644 index 0000000..83c831f --- /dev/null +++ b/public/index.gmi @@ -0,0 +1 @@ +# test