-
-
Notifications
You must be signed in to change notification settings - Fork 133
/
server.py
60 lines (50 loc) · 1.66 KB
/
server.py
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
# SPDX-FileCopyrightText: 2022 Konstantinos Thoukydidis <[email protected]>
#
# SPDX-License-Identifier: AGPL-3.0-or-later
import logging
import os
from dotenv import load_dotenv
profile = os.environ.get("PROFILE")
if profile is not None:
env_file = f".env_{profile}"
load_dotenv(env_file)
else:
load_dotenv()
from horde.argparser import args
from horde.flask import HORDE
from horde.logger import logger
from horde.metrics import waitress_metrics
if __name__ == "__main__":
# Only setting this for the WSGI logs
logging.basicConfig(
format="%(asctime)s - %(levelname)s - %(module)s:%(lineno)d - %(message)s",
level=logging.WARNING,
)
import waitress
# Monkeypatch to get metrics until below is done
# https://github.com/Pylons/waitress/issues/182
_create_server = waitress.create_server
def create_server(*args, **kwargs):
server = _create_server(*args, **kwargs)
waitress_metrics.setup(server.task_dispatcher)
return server
waitress.create_server = create_server
logger.init("WSGI Server", status="Starting")
url_scheme = "https"
if args.insecure:
os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1" # Disable this on prod
url_scheme = "http"
allowed_host = "stablehorde.net"
if args.insecure:
allowed_host = "0.0.0.0"
logger.init_warn("WSGI Mode", status="Insecure")
waitress.serve(
HORDE,
port=args.port,
url_scheme=url_scheme,
threads=45,
connection_limit=1024,
asyncore_use_poll=True,
)
# HORDE.run(debug=True,host="0.0.0.0",port="5001")
logger.init("WSGI Server", status="Stopped")