-
-
Save rcowsill/2590c8dcc469fe12ea3f710d57b970cc to your computer and use it in GitHub Desktop.
Minimal python http server (works on Windows)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import http.server | |
import socketserver | |
HOST = "localhost" | |
PORT = 8080 | |
class HttpRequestHandler(http.server.SimpleHTTPRequestHandler): | |
extensions_map = { | |
".js":"text/javascript", | |
} | |
httpd = socketserver.TCPServer((HOST, PORT), HttpRequestHandler) | |
try: | |
print(f"serving at http://{HOST}:{PORT}") | |
httpd.serve_forever() | |
except KeyboardInterrupt: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Minimal server for local development that works on Windows.
Based on original gist, updated with suggestions from @asynts (here), @jan25 (here) and @scottj (here)
The override is needed to ensure the correct MIME type is used when serving javascript. The default mapping comes from the registry, which says .js files are
text/plain
. See python/cpython#88141.