fileserver!

Signed-off-by: Christine Dodrill <me@christine.website>
This commit is contained in:
Cadey Ratio 2021-05-10 20:00:31 +00:00
parent 0e0af9afa5
commit 873fe3f7d9
4 changed files with 23 additions and 5 deletions

View File

@ -16,15 +16,13 @@ class Server
@cq\wrap -> @cq\wrap ->
with conn with conn
_, ip = \peername! _, ip = \peername!
pid, uid, gid = \peerpid!, \peereid!
request = \read "*l" request = \read "*l"
\shutdown "r" \shutdown "r"
u = url.parse request u = url.parse request
if u.path == ""
u.path = "/"
ctx = ctx =
:ip :ip
:pid
:uid
:gid
host: u.host host: u.host
path: u.path path: u.path
query: u.query query: u.query

View File

@ -11,7 +11,25 @@ class ProxyRequestRefusedHandler
conn\write "53 Proxy request refused \r\n" conn\write "53 Proxy request refused \r\n"
ln.log ctx, {status: 53} 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 "127.0.0.1", "58816"
\listen socket.listen \listen socket.listen
path: "./var/mipha.sock" path: "./var/mipha.sock"

1
public/foo.gmi Normal file
View File

@ -0,0 +1 @@
# foo

1
public/index.gmi Normal file
View File

@ -0,0 +1 @@
# test