diff options
Diffstat (limited to 'server.py')
-rwxr-xr-x | server.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/server.py b/server.py new file mode 100755 index 0000000..9e81820 --- /dev/null +++ b/server.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python + +import http.server +import os + + +class NoCacheHTTPRequestHandler(http.server.SimpleHTTPRequestHandler): + def end_headers(self): + self.send_header('Cache-Control', 'no-cache, no-store, must-revalidate') # HTTP 1.1 + self.send_header('Pragma', 'no-cache') # HTTP 1.0 + self.send_header('Expires', '0') # Proxies + super().end_headers() + + +def run(server_class=http.server.HTTPServer, port=8080, directory="./result"): + # Set the directory for the handler + handler_class = NoCacheHTTPRequestHandler + handler_class.directory = os.path.abspath(directory) + + # Change the current working directory to the specified directory + os.chdir(os.path.abspath(directory)) + + # Create the server on 127.0.0.1 + with server_class(("127.0.0.1", port), handler_class) as httpd: + print( + f"Serving on http://127.0.0.1:{port} from directory '{handler_class.directory}'" + ) + httpd.serve_forever() + + +if __name__ == "__main__": + run(port=8080, directory="./result") |