Skip to content

Instantly share code, notes, and snippets.

@rikvermeer
Last active June 20, 2019 19:49
Show Gist options
  • Save rikvermeer/3c40d6a92dfa12a65ea5aae1ef8edc21 to your computer and use it in GitHub Desktop.
Save rikvermeer/3c40d6a92dfa12a65ea5aae1ef8edc21 to your computer and use it in GitHub Desktop.
Simple HTTP server with mime-types
#!/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