-
-
Notifications
You must be signed in to change notification settings - Fork 325
/
Copy pathapp.py
60 lines (39 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import os
from logging import getLogger
from pathlib import Path
from sanic import Sanic, response
from idom.server.sanic import PerClientStateServer
from idom.widgets import multiview
from .examples import load_examples
HERE = Path(__file__).parent
IDOM_MODEL_SERVER_URL_PREFIX = "/_idom"
logger = getLogger(__name__)
IDOM_MODEL_SERVER_URL_PREFIX = "/_idom"
def run():
app = make_app()
PerClientStateServer(
make_examples_component(),
{
"redirect_root_to_index": False,
"url_prefix": IDOM_MODEL_SERVER_URL_PREFIX,
},
app,
)
app.run(
host="0.0.0.0",
port=int(os.environ.get("PORT", 5000)),
workers=int(os.environ.get("WEB_CONCURRENCY", 1)),
debug=bool(int(os.environ.get("DEBUG", "0"))),
)
def make_app():
app = Sanic(__name__)
app.static("/docs", str(HERE / "build"))
@app.route("/")
async def forward_to_index(request):
return response.redirect("/docs/index.html")
return app
def make_examples_component():
mount, component = multiview()
for example_name, example_component in load_examples():
mount.add(example_name, example_component)
return component