From 9447d4e3de759dae7692b4d9e2f39433c3752a12 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Tue, 21 Jan 2020 08:26:22 -0700 Subject: [PATCH] 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()