# -*- coding: utf-8 -*-
# dzw_viewer_server.py — 뷰어 정적 서버 (캐시 완전 차단) [2026-07-07]
#   python -m http.server 는 Last-Modified로 브라우저 캐시를 유발 → 수정해도 옛 버전 로드.
#   이 서버는 Cache-Control: no-store 로 매번 최신 파일을 강제 로드.
import http.server, socketserver, os

PORT = 8090
ROOT = os.path.dirname(os.path.abspath(__file__))

class NoCacheHandler(http.server.SimpleHTTPRequestHandler):
    def __init__(self, *a, **k): super().__init__(*a, directory=ROOT, **k)
    def end_headers(self):
        self.send_header('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0')
        self.send_header('Pragma', 'no-cache')
        self.send_header('Expires', '0')
        super().end_headers()
    def log_message(self, *a): pass

if __name__ == '__main__':
    socketserver.TCPServer.allow_reuse_address = True
    with socketserver.ThreadingTCPServer(('0.0.0.0', PORT), NoCacheHandler) as httpd:
        print('[뷰어서버] http://0.0.0.0:%d (캐시 차단) — %s' % (PORT, ROOT))
        httpd.serve_forever()
