From d95f4fa4bf5af09d755600dd8e5a4557623bfdd4 Mon Sep 17 00:00:00 2001 From: kushidou Date: Sat, 18 Jul 2026 20:44:14 +0800 Subject: [PATCH] feat: add local Python development server --- start_server.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 start_server.py diff --git a/start_server.py b/start_server.py new file mode 100644 index 0000000..d1de57a --- /dev/null +++ b/start_server.py @@ -0,0 +1,30 @@ +#!/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服务器已停止。')