You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importhttp.serverimportsocketserverimportosDIRECTORY="/Users/agah/Downloads/LivingPreprint_10.55458_NeuroLibre_00031_33723c"BASE_URL="/10.55458/neurolibre.00031"classCustomHandler(http.server.SimpleHTTPRequestHandler):
deftranslate_path(self, path):
# Remove the base URL prefix from the pathifpath.startswith(BASE_URL):
path=path[len(BASE_URL):]
# Serve files from the specified directorypath=os.path.join(DIRECTORY, path.lstrip("/"))
returnpathdefdo_GET(self):
# Check if the requested file existsfile_path=self.translate_path(self.path)
ifnotos.path.exists(file_path):
# If file doesn't exist, try appending `.html`file_path+=".html"ifos.path.exists(file_path):
# Update the path to point to the .html fileself.path+=".html"# Call the parent class's GET handlersuper().do_GET()
# Set the port for the serverPORT=8000withsocketserver.TCPServer(("", PORT), CustomHandler) ashttpd:
print(f"Serving at http://localhost:{PORT}{BASE_URL}")
httpd.serve_forever()
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: