diff --git a/scripts/autoserve.py b/scripts/autoserve.py index ed1fb51..87d6b41 100644 --- a/scripts/autoserve.py +++ b/scripts/autoserve.py @@ -55,16 +55,24 @@ class Server(http.server.SimpleHTTPRequestHandler): time.sleep(SLEEP_TIME) return + path = self.path + if path.strip('/') == '': + path = '/index.html' + if os.path.isdir(path.strip('/')): + if path.endswith('/'): + path = path.strip('/') + '/index.html' + else: + # Redirect to + / + self.send_response(301) + self.send_header('Location', path + '/') + self.end_headers() + return + # send 200 response self.send_response(200) # send response headers self.end_headers() - path = self.path - if path.strip('/') == '': - path = '/index.html' - if os.path.isdir(path.strip('/')): - path = path.strip('/') + '/index.html' with open(path.strip('/'), 'rb') as f: # send the body of the response self.wfile.write(f.read())