This repository was archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathdebug_main.py
More file actions
86 lines (63 loc) · 2.19 KB
/
debug_main.py
File metadata and controls
86 lines (63 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# -*- coding: utf-8 -*-
#
# If you want to run this file, please install following package to run.
# python3 -m pip install werkzeug 'uvicorn[standard]'
#
from naja_atra import request_map
import naja_atra.server as server
import os
import signal
from naja_atra.http_servers.http_server import HttpServer
from naja_atra.utils.logger import get_logger, set_level
from naja_atra import get_app_conf
set_level("DEBUG")
@request_map("/stop")
def stop():
server.stop()
return "<!DOCTYPE html><html><head><title>关闭</title></head><body>关闭成功!</body></html>"
_logger = get_logger("http_test")
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
_server: HttpServer = None
app = get_app_conf("2")
@app.route("/")
def idx():
return {"msg": "hello, world!"}
def start_via_class():
global _server
_server = HttpServer(host=('', 9091),
resources={"/p/**": f"{PROJECT_ROOT}/tests/static"},
app_conf=app)
_server.start()
def start_server():
_logger.info("start server in background. ")
server.scan(base_dir="tests/ctrls", regx=r'.*controllers.*')
server.start(
# port=9443,
port=9090,
resources={"/public/*": f"{PROJECT_ROOT}/tests/static",
"/*": f"{PROJECT_ROOT}/tests/static",
'/inn/**': f"{PROJECT_ROOT}/tests/static",
'**.txt': f"{PROJECT_ROOT}/tests/static",
'*.ini': f"{PROJECT_ROOT}/tests/static",
},
# ssl=True,
# certfile=f"{PROJECT_ROOT}/tests/certs/fullchain.pem",
# keyfile=f"{PROJECT_ROOT}/tests/certs//privkey.pem",
gzip_content_types={"image/x-icon", "text/plain"},
gzip_compress_level=9,
prefer_coroutine=False)
def on_sig_term(signum, frame):
server.stop()
if _server:
_server.shutdown()
if __name__ == "__main__":
signal.signal(signal.SIGTERM, on_sig_term)
signal.signal(signal.SIGINT, on_sig_term)
# Thread(target=start_via_class, daemon=True).start()
# sleep(1)
# start_via_class()
# main(sys.argv[1:])
start_server()
# start_server_wsgi()
# start_server_werkzeug()
# start_server_uvicorn()