Last active
June 20, 2019 19:49
-
-
Save rikvermeer/3c40d6a92dfa12a65ea5aae1ef8edc21 to your computer and use it in GitHub Desktop.
Simple HTTP server with mime-types
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
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
import http.server | |
from http.server import HTTPServer, BaseHTTPRequestHandler | |
import socketserver | |
from random import randint | |
PORT = randint(1024, 65536) | |
Handler = http.server.SimpleHTTPRequestHandler | |
Handler.extensions_map={ | |
'.manifest': 'text/cache-manifest', | |
'.html': 'text/html', | |
'.png': 'image/png', | |
'.jpg': 'image/jpg', | |
'.svg': 'image/svg+xml', | |
'.css': 'text/css', | |
'.js': 'application/x-javascript', | |
'.wasm': 'application/wasm', | |
'': 'application/octet-stream', | |
} | |
httpd = socketserver.TCPServer(("", PORT), Handler) | |
print("serving at port", PORT) | |
import webbrowser | |
webbrowser.open('http://0.0.0.0:%d' % PORT) | |
httpd.serve_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment