From 9447d4e3de759dae7692b4d9e2f39433c3752a12 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Tue, 21 Jan 2020 08:26:22 -0700 Subject: [PATCH 1/3] Add a MIME-type for .mjs files --- devel/devel-server.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/devel/devel-server.py b/devel/devel-server.py index 0d775dc..31e6f12 100755 --- a/devel/devel-server.py +++ b/devel/devel-server.py @@ -1,6 +1,5 @@ #!/usr/bin/python3 -import asyncio import cgitb import html import cgi @@ -42,7 +41,15 @@ class MothRequestHandler(http.server.SimpleHTTPRequestHandler): super().__init__(request, client_address, server, directory=server.args["theme_dir"]) except TypeError: super().__init__(request, client_address, server) + # Why can't they just use mimetypes?! + # Why isn't this the default?! + def guess_type(self, path): + mtype, encoding = mimetypes.guess_type(path) + if encoding: + return "%s; encoding=%s" % (mtype, encoding) + else: + return mtype # Backport from Python 3.7 def translate_path(self, path): @@ -285,10 +292,13 @@ if __name__ == '__main__': logging.basicConfig(level=log_level) + mimetypes.add_type("application/javascript", ".mjs") + server = MothServer((addr, port), MothRequestHandler) server.args["base_url"] = args.base server.args["puzzles_dir"] = pathlib.Path(args.puzzles) server.args["theme_dir"] = args.theme + logging.info("Listening on %s:%d", addr, port) server.serve_forever() From d3389d5bf127a56efeb48efa665802ab2bb170d3 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Tue, 21 Jan 2020 08:29:08 -0700 Subject: [PATCH 2/3] Remove superfluous comment --- devel/devel-server.py | 1 - 1 file changed, 1 deletion(-) diff --git a/devel/devel-server.py b/devel/devel-server.py index 31e6f12..fd53d12 100755 --- a/devel/devel-server.py +++ b/devel/devel-server.py @@ -41,7 +41,6 @@ class MothRequestHandler(http.server.SimpleHTTPRequestHandler): super().__init__(request, client_address, server, directory=server.args["theme_dir"]) except TypeError: super().__init__(request, client_address, server) - # Why can't they just use mimetypes?! # Why isn't this the default?! def guess_type(self, path): From f643f7b754e0dbcd176dcfbb6ead9dbedad8e203 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Tue, 21 Jan 2020 08:29:25 -0700 Subject: [PATCH 3/3] Remove superfluous newline --- devel/devel-server.py | 1 - 1 file changed, 1 deletion(-) diff --git a/devel/devel-server.py b/devel/devel-server.py index fd53d12..7d7b505 100755 --- a/devel/devel-server.py +++ b/devel/devel-server.py @@ -297,7 +297,6 @@ if __name__ == '__main__': server.args["base_url"] = args.base server.args["puzzles_dir"] = pathlib.Path(args.puzzles) server.args["theme_dir"] = args.theme - logging.info("Listening on %s:%d", addr, port) server.serve_forever()