Иван Солнцев
c9154cdb08
Change name from start_http_server() to init_server_socket(). Improvements: - Change child threads to daemon type; - Send client HTTP error codes & add new HTTP codes description; - Change log output format; - Add some debug log strings; Remove: - Startup ASCII logo;
33 lines
957 B
Python
33 lines
957 B
Python
import os
|
|
import logging
|
|
|
|
from server.common import HandlerType, HTTPMethod
|
|
from server.urlhandler import Path
|
|
import testmod
|
|
|
|
|
|
SETUP = {
|
|
"setup": {
|
|
"log_to_file": False,
|
|
"log_level": logging.DEBUG
|
|
},
|
|
"server": {
|
|
"port": 8080,
|
|
}
|
|
}
|
|
|
|
|
|
if SETUP["setup"]["log_to_file"]:
|
|
logging.basicConfig(filename=os.path.join(os.getcwd(), "log", "main.log"), filemode="a", encoding="UTF-8",
|
|
level=SETUP["setup"]["log_level"],
|
|
format="[%(asctime)s][%(levelname)s][%(name)s] %(message)s")
|
|
else:
|
|
logging.basicConfig(encoding="UTF-8", level=SETUP["setup"]["log_level"],
|
|
format="[%(asctime)s][%(levelname)s][%(name)s] %(message)s")
|
|
|
|
|
|
urls = [
|
|
Path("/", HandlerType.STATIC_FILE, "index.html"),
|
|
Path("/func", HandlerType.FUNCTION, testmod.work, HTTPMethod.GET|HTTPMethod.POST),
|
|
Path("/func1", HandlerType.FUNCTION, testmod.work2, HTTPMethod.POST)
|
|
]
|