Created
May 18, 2014 14:00
-
-
Save HaiyangXu/ec88cbdce3cdbac7b8d5 to your computer and use it in GitHub Desktop.
A simper python http server can handle mime type properly
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
# -*- coding: utf-8 -*- | |
#test on python 3.4 ,python of lower version has different module organization. | |
import http.server | |
from http.server import HTTPServer, BaseHTTPRequestHandler | |
import socketserver | |
PORT = 8080 | |
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', | |
'': 'application/octet-stream', # Default | |
} | |
httpd = socketserver.TCPServer(("", PORT), Handler) | |
print("serving at port", PORT) | |
httpd.serve_forever() |
Thanks! Also, for cleanup of server i used context manager around httpd.
with socketserver.TCPServer(("", PORT), Handler) as httpd:
print("serving at port", PORT)
httpd.serve_forever()
wasm support: add
'.wasm': 'application/wasm',
yessss
'.js':'application/x-javascript',
Maybe a line for '.mjs' (ES6 module) files too?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice updates. Thanks @asynts!