Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@planetsizebrain
Created October 23, 2016 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save planetsizebrain/6e0b4a772ce1873fbe2d8326fc9514cb to your computer and use it in GitHub Desktop.
Save planetsizebrain/6e0b4a772ce1873fbe2d8326fc9514cb to your computer and use it in GitHub Desktop.
A small extension of the default Python SimpleHTTPServer that ignores the first part of the URL
import BaseHTTPServer
import SimpleHTTPServer
class MyRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def translate_path(self, path):
index = path.find('/', 2)
return SimpleHTTPServer.SimpleHTTPRequestHandler.translate_path(self, path[index:])
httpd = BaseHTTPServer.HTTPServer(server_address, MyRequestHandler)
httpd.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment