1 Star 0 Fork 0

dengwenshan/quicknote

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
server.py 1.32 KB
一键复制 编辑 原始数据 按行查看 历史
dengwenshan 提交于 2024-12-12 15:16 . Initial commit: QuickNote project
from http.server import HTTPServer, SimpleHTTPRequestHandler
import socket
import sys
import webbrowser
import os
class CustomHandler(SimpleHTTPRequestHandler):
def end_headers(self):
self.send_header('Cache-Control', 'no-store, no-cache, must-revalidate')
self.send_header('Access-Control-Allow-Origin', '*')
SimpleHTTPRequestHandler.end_headers(self)
def run(port=8000):
try:
server_address = ('', port)
httpd = HTTPServer(server_address, CustomHandler)
print(f'Starting server on port {port}...')
print(f'Visit http://localhost:{port}')
# 自动打开浏览器
webbrowser.open(f'http://localhost:{port}')
httpd.serve_forever()
except socket.error as e:
if e.errno == 10013:
print(f"Error: Port {port} requires elevated privileges.")
print("Try using a port number above 1024")
sys.exit(1)
elif e.errno == 10048:
print(f"Error: Port {port} is already in use.")
print("Try a different port number")
sys.exit(1)
else:
raise e
except KeyboardInterrupt:
print("\nShutting down server...")
httpd.server_close()
sys.exit(0)
if __name__ == '__main__':
run(8000)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/Wenshandeng/quicknote.git
git@gitee.com:Wenshandeng/quicknote.git
Wenshandeng
quicknote
quicknote
main

搜索帮助