From fea2d91d1eafbb313421efa196e5b421d56e51c1 Mon Sep 17 00:00:00 2001 From: Michael Lazar Date: Fri, 23 Aug 2019 09:45:24 -0400 Subject: [PATCH] Update default index file --- CHANGELOG.md | 7 +++++++ jetforce.py | 21 +++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f0f261..616fa72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Jetforce Changelog +### Unreleased + +- Files with the ".gemini" extension are now recognized as text/gemini. +- The default index file has been changed from ".gemini" to "index.gmi". +- Added a new --index-file flag that can be used to customize the name of the + gemini file that will be served when a directory is requested. + ### v0.0.6 (2019-08-22) - Significant refactoring of the base application interface. diff --git a/jetforce.py b/jetforce.py index 3ebc4ee..dc75879 100755 --- a/jetforce.py +++ b/jetforce.py @@ -198,13 +198,15 @@ class StaticDirectoryApplication(JetforceApplication): directory listing will be auto-generated. """ - def __init__(self, directory: str = "/var/gemini"): + def __init__(self, directory: str = "/var/gemini", index_file: str = "index.gmi"): super().__init__() self.routes.append((RoutePattern(), self.serve_static_file)) self.root = pathlib.Path(directory).resolve(strict=True) + self.index_file = index_file self.mimetypes = mimetypes.MimeTypes() self.mimetypes.add_type("text/gemini", ".gmi") + self.mimetypes.add_type("text/gemini", ".gemini") def serve_static_file(self, request: Request): @@ -222,9 +224,9 @@ class StaticDirectoryApplication(JetforceApplication): generator = self.load_file(filesystem_path) return Response(Status.SUCCESS, mimetype, generator) elif filesystem_path.is_dir(): - gemini_file = filesystem_path / ".gemini" - if gemini_file.exists(): - generator = self.load_file(gemini_file) + index_file = filesystem_path / self.index_file + if index_file.exists(): + generator = self.load_file(index_file) else: generator = self.list_directory(url_path, filesystem_path) return Response(Status.SUCCESS, "text/gemini", generator) @@ -519,10 +521,17 @@ def run_server() -> None: Entry point for running the command line static directory server. """ parser = command_line_parser() - parser.add_argument("--dir", help="local directory to serve", default="/var/gemini") + parser.add_argument( + "--dir", help="Path on the filesystem to serve", default="/var/gemini" + ) + parser.add_argument( + "--index-file", + help="The gemini directory index file [i.e. index.html]", + default="index.gmi", + ) args = parser.parse_args() - app = StaticDirectoryApplication(args.dir) + app = StaticDirectoryApplication(args.dir, args.index_file) server = GeminiServer( host=args.host, port=args.port,