Skip to content

Commit 616adfa

Browse files
committed
use sanic redirect url_for
1 parent 260553f commit 616adfa

File tree

2 files changed

+13
-69
lines changed

2 files changed

+13
-69
lines changed

examples/introduction.ipynb

Lines changed: 8 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
},
4848
{
4949
"cell_type": "code",
50-
"execution_count": 1,
50+
"execution_count": null,
5151
"metadata": {},
5252
"outputs": [],
5353
"source": [
@@ -65,17 +65,9 @@
6565
},
6666
{
6767
"cell_type": "code",
68-
"execution_count": 2,
69-
"metadata": {},
70-
"outputs": [
71-
{
72-
"name": "stdout",
73-
"output_type": "stream",
74-
"text": [
75-
"[2020-04-22 17:37:27 -0700] [3083] [INFO] Goin' Fast @ http://127.0.0.1:8765\n"
76-
]
77-
}
78-
],
68+
"execution_count": null,
69+
"metadata": {},
70+
"outputs": [],
7971
"source": [
8072
"from idom.server.sanic import PerClientState\n",
8173
"from example_utils import setup_example_server, display_href, pretty_dict_string\n",
@@ -98,7 +90,7 @@
9890
},
9991
{
10092
"cell_type": "code",
101-
"execution_count": 3,
93+
"execution_count": null,
10294
"metadata": {},
10395
"outputs": [],
10496
"source": [
@@ -123,61 +115,9 @@
123115
},
124116
{
125117
"cell_type": "code",
126-
"execution_count": 4,
127-
"metadata": {},
128-
"outputs": [
129-
{
130-
"name": "stdout",
131-
"output_type": "stream",
132-
"text": [
133-
"Try clicking the image! 🖱️\n"
134-
]
135-
},
136-
{
137-
"data": {
138-
"text/html": [
139-
"<script>document.idomServerExists = true;</script>"
140-
]
141-
},
142-
"metadata": {},
143-
"output_type": "display_data"
144-
},
145-
{
146-
"data": {
147-
"text/html": [
148-
"\n",
149-
" <div id=\"idom-2dbb91f1d1c948adab63c95854c5b9db\" class=\"idom-widget\"/>\n",
150-
" \n",
151-
" <script type=\"module\">\n",
152-
" // we want to avoid making this request (in case of CORS)\n",
153-
" // unless we know an IDOM server is expected to respond\n",
154-
" if (document.idomServerExists) {\n",
155-
" const loc = {\"host\": \"127.0.0.1:8765\", \"protocol\": \"http:\"};\n",
156-
" const idom_url = \"//\" + loc.host + \"\";\n",
157-
" const http_proto = loc.protocol;\n",
158-
" const ws_proto = (http_proto === \"https:\") ? \"wss:\" : \"ws:\";\n",
159-
" import(http_proto + idom_url + \"/client/core_modules/layout.js\").then(\n",
160-
" (module) => {\n",
161-
" module.renderLayout(\n",
162-
" document.getElementById(\"idom-2dbb91f1d1c948adab63c95854c5b9db\"),\n",
163-
" ws_proto + idom_url + \"/stream\"\n",
164-
" );\n",
165-
" }\n",
166-
" );\n",
167-
" }\n",
168-
" </script>\n",
169-
" \n",
170-
" "
171-
],
172-
"text/plain": [
173-
"JupyterWigdet('')"
174-
]
175-
},
176-
"execution_count": 4,
177-
"metadata": {},
178-
"output_type": "execute_result"
179-
}
180-
],
118+
"execution_count": null,
119+
"metadata": {},
120+
"outputs": [],
181121
"source": [
182122
"print(\"Try clicking the image! 🖱️\")\n",
183123
"\n",

idom/server/sanic.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ def _setup_application(self, app: Sanic, config: Config) -> None:
5656
app.route("/favicon.ico")(
5757
lambda r: response.redirect("/client/favicon.ico")
5858
)
59-
app.route(url_prefix + "/")(lambda r: response.redirect("./client/index.html"))
59+
60+
@app.route(url_prefix + "/")
61+
def redirect_to_index(request):
62+
return response.redirect(app.url_for("_client_route", path="index.html"))
63+
6064
app.websocket(url_prefix + "/stream")(self._stream_route)
6165

6266
def _run_application(

0 commit comments

Comments
 (0)