-
Notifications
You must be signed in to change notification settings - Fork 7
/
app.py
43 lines (31 loc) · 1.2 KB
/
app.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
import logging
import sys
import urllib.parse
from palace.manager.api.app import initialize_application
from palace.manager.scripts.initialization import InstanceInitializationScript
def run(url=None):
base_url = url or "http://localhost:6500/"
scheme, netloc, path, parameters, query, fragment = urllib.parse.urlparse(base_url)
if ":" in netloc:
host, port = netloc.split(":")
port = int(port)
else:
host = netloc
port = 80
debug = True
# Workaround for a "Resource temporarily unavailable" error when
# running in debug mode with the global socket timeout set by isbnlib
if debug:
import socket
socket.setdefaulttimeout(None)
# Setup database by initializing it or running migrations
InstanceInitializationScript().run()
app = initialize_application()
# Required for subdomain support.
app.config["SERVER_NAME"] = netloc
logging.info("Starting app on %s:%s", host, port)
sslContext = "adhoc" if scheme == "https" else None
app.run(debug=debug, host=host, port=port, threaded=True, ssl_context=sslContext)
if __name__ == "__main__":
url = sys.argv.pop() if len(sys.argv) > 1 else None
run(url)