29 lines
1.0 KiB
Python
29 lines
1.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Serve the deck for editing: like `python3 -m http.server`, but every
|
|
response says Cache-Control: no-store, so a plain reload always shows the
|
|
files as they are on disk. (The stock server sends Last-Modified and nothing
|
|
else, and browsers then keep the section files and the CSS for a while.)
|
|
|
|
python3 slides/serve.py # http://localhost:8765
|
|
python3 slides/serve.py 8000
|
|
"""
|
|
import os
|
|
import sys
|
|
from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer
|
|
|
|
|
|
class NoCacheHandler(SimpleHTTPRequestHandler):
|
|
def end_headers(self):
|
|
self.send_header("Cache-Control", "no-store")
|
|
super().end_headers()
|
|
|
|
def log_message(self, fmt, *args):
|
|
pass # quiet; errors still go through log_error
|
|
|
|
|
|
if __name__ == "__main__":
|
|
port = int(sys.argv[1]) if len(sys.argv) > 1 else 8765
|
|
os.chdir(os.path.dirname(os.path.abspath(__file__)))
|
|
print(f"serving {os.getcwd()} on http://localhost:{port}/")
|
|
ThreadingHTTPServer(("", port), NoCacheHandler).serve_forever()
|