diff options
Diffstat (limited to '')
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | flake.nix | 1 | ||||
-rwxr-xr-x | server.py | 32 |
3 files changed, 34 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore index 9a899cc..aab76ce 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .direnv /result +__pycache__ diff --git a/flake.nix b/flake.nix index 5e4e91b..6bc34fc 100644 --- a/flake.nix +++ b/flake.nix @@ -135,6 +135,7 @@ default = pkgs.mkShell { packages = [ pkgs.zola + pkgs.python3 ]; }; }; 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") |