Merge pull request #122 from dirtbags/mjs

Add a MIME-type for .mjs files
This commit is contained in:
int00h5525 2020-01-21 09:45:07 -06:00 committed by GitHub
commit 8809580355
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 1 deletions

View File

@ -1,6 +1,5 @@
#!/usr/bin/python3 #!/usr/bin/python3
import asyncio
import cgitb import cgitb
import html import html
import cgi import cgi
@ -43,6 +42,13 @@ class MothRequestHandler(http.server.SimpleHTTPRequestHandler):
except TypeError: except TypeError:
super().__init__(request, client_address, server) super().__init__(request, client_address, server)
# 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 # Backport from Python 3.7
def translate_path(self, path): def translate_path(self, path):
@ -285,6 +291,8 @@ if __name__ == '__main__':
logging.basicConfig(level=log_level) logging.basicConfig(level=log_level)
mimetypes.add_type("application/javascript", ".mjs")
server = MothServer((addr, port), MothRequestHandler) server = MothServer((addr, port), MothRequestHandler)
server.args["base_url"] = args.base server.args["base_url"] = args.base
server.args["puzzles_dir"] = pathlib.Path(args.puzzles) server.args["puzzles_dir"] = pathlib.Path(args.puzzles)