Skip to content

Instantly share code, notes, and snippets.

@kristoferjoseph
Forked from HaiyangXu/Server.py
Last active June 25, 2021 09:54
Show Gist options
  • Save kristoferjoseph/b23eda37f1e57e627a931a50eb47f0af to your computer and use it in GitHub Desktop.
Save kristoferjoseph/b23eda37f1e57e627a931a50eb47f0af to your computer and use it in GitHub Desktop.
A simper python http server can handle mime type properly
# -*- 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',
'.mjs': 'text/javascript',
'': 'application/octet-stream', # Default
}
httpd = socketserver.TCPServer(("", PORT), Handler)
print("serving at port", PORT)
httpd.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment