From df7267af48251bc9c333321d80fe3f3018041c03 Mon Sep 17 00:00:00 2001 From: Micke Nordin Date: Tue, 16 Feb 2021 16:15:28 +0100 Subject: [PATCH] Add info on how to run --- README.md | 17 +++++++++++++++-- content/test/file.gmi | 4 ++++ content/test/file.txt | 2 ++ gmnd/__init__.py | 21 +++++++++++++++------ 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 6a7a049..47aa32e 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,15 @@ -# gmnd -My gemini server +# gMNd +gMNd is my gemini server, which is written in python. + +Currently it only serves static files. You can build and run it from the supplied Dockerfile if you so whish +``` +docker build -t gmnd:latest . +``` +By just running it, it will create self signed certs and serve example content from this repo +``` +docker run -p 1965:1965 gmnd +``` +A slightly more interesting thing it can do is serve your own content, in this example from /tm/content on your host machine +``` +docker run --mount type=bind,source="/tmp/content,target=/app/content" -p 1965:1965 gmnd +``` diff --git a/content/test/file.gmi b/content/test/file.gmi index e69de29..b074c83 100644 --- a/content/test/file.gmi +++ b/content/test/file.gmi @@ -0,0 +1,4 @@ +# Heading test + +* item +* item 2 diff --git a/content/test/file.txt b/content/test/file.txt index e69de29..896eb4c 100644 --- a/content/test/file.txt +++ b/content/test/file.txt @@ -0,0 +1,2 @@ +# Text +Plain text me old son diff --git a/gmnd/__init__.py b/gmnd/__init__.py index c76642f..60ed570 100644 --- a/gmnd/__init__.py +++ b/gmnd/__init__.py @@ -1,4 +1,5 @@ import logging +import mimetypes import os import socket import ssl @@ -48,6 +49,11 @@ class gMNd: header = get_header() body = b"" if os.path.isfile(self.base_path + path): + if not path.endswith(".gmi"): + header = get_header( + '20', + mimetypes.guess_type( + self.base_path + path)[0].encode()) cfile = open(self.base_path + path) body = cfile.read().encode() cfile.close() @@ -71,7 +77,7 @@ class gMNd: conn.shutdown(socket.SHUT_RDWR) conn.close() - def get_dir_list(self,directory): + def get_dir_list(self, directory): contents = b"#Contents:\r\n" dirs = [] files = [] @@ -90,20 +96,23 @@ class gMNd: return contents -def get_header(status='20', meta = b""): +def get_header(status='20', meta=b"text/gemini"): metadict = {} metadict['10'] = meta - metadict['20'] = b"text/gemini" + metadict['20'] = meta metadict['30'] = meta metadict['40'] = meta metadict['50'] = meta metadict['60'] = b"Client certificate required" separator = b" " terminator = b"\r\n" - header = bytes(status.encode()) + separator + metadict[status] + terminator - return header + header = bytes(status.encode()) + separator + metadict[status] + terminator + return header if __name__ == "__main__": - server = gMNd({'allow_dir_list': True, 'logg_level': logging.DEBUG, 'listen_addr': '0.0.0.0'}) + server = gMNd({ + 'allow_dir_list': True, + 'listen_addr': '0.0.0.0' + }) server.run()