#!/usr/bin/env python3 """Local development server for PC Configuration Builder.""" import http.server import os import sys PORT = 8080 class CORSHandler(http.server.SimpleHTTPRequestHandler): def end_headers(self): self.send_header('Access-Control-Allow-Origin', '*') super().end_headers() def log_message(self, format, *args): print(f'[{self.log_date_time_string()}] {format % args}') if __name__ == '__main__': os.chdir(os.path.dirname(os.path.abspath(__file__))) with http.server.HTTPServer(('', PORT), CORSHandler) as httpd: print(f'PC装机配置表 - 开发服务器') print(f'服务地址: http://localhost:{PORT}') print(f'打开页面: http://localhost:{PORT}/?config=sample_config.json') print(f'按 Ctrl+C 停止服务器') print() try: httpd.serve_forever() except KeyboardInterrupt: print('\n服务器已停止。')