Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2db6d0c

Browse files
Use port as argument to ensure backwards compat
Co-Authored-By: Audrey M. Roy Greenfeld <audrey@feldroy.com>
1 parent28df044 commit2db6d0c

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

‎fastcaddy/core.py‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
importos,subprocess,httpx,json
1313
fromfastcore.utilsimport*
1414
fromhttpximportHTTPStatusError,getasxget,postasxpost,patchasxpatch,putasxput,deleteasxdelete,headasxhead
15+
fromtypingimportSequence
1516

1617
# %% ../nbs/00_core.ipynb 5
1718
defget_id(path):
@@ -177,12 +178,17 @@ def add_wildcard_route(domain):
177178
add_route(route)
178179

179180
# %% ../nbs/00_core.ipynb 48
180-
defadd_sub_reverse_proxy(domain,subdomain,ports,host='localhost'):
181+
defadd_sub_reverse_proxy(
182+
domain,
183+
subdomain,
184+
port:str|int|Sequence[str|int],# A single port or list of ports
185+
host='localhost'
186+
):
181187
"Add a reverse proxy to a wildcard subdomain supporting multiple ports"
182188
wildcard_id=f"wildcard-{domain}"
183189
route_id=f"{subdomain}.{domain}"
184-
ifisinstance(ports, (int,str)):ports= [ports]
185-
upstreams= [{"dial":f"{host}:{port}"}forportinports]
190+
ifisinstance(port, (int,str)):port= [port]
191+
upstreams= [{"dial":f"{host}:{p}"}forpinport]
186192
new_route= {
187193
"@id":route_id,
188194
"match": [{"host": [route_id]}],

‎nbs/00_core.ipynb‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
"#| export\n",
3535
"import os, subprocess, httpx, json\n",
3636
"from fastcore.utils import *\n",
37-
"from httpx import HTTPStatusError, get as xget, post as xpost, patch as xpatch, put as xput, delete as xdelete, head as xhead"
37+
"from httpx import HTTPStatusError, get as xget, post as xpost, patch as xpatch, put as xput, delete as xdelete, head as xhead\n",
38+
"from typing import Sequence"
3839
]
3940
},
4041
{
@@ -599,7 +600,7 @@
599600
"metadata": {},
600601
"outputs": [],
601602
"source": [
602-
"#add_wildcard_route('something.fast.ai')"
603+
"add_wildcard_route('something.fast.ai')"
603604
]
604605
},
605606
{
@@ -609,12 +610,17 @@
609610
"outputs": [],
610611
"source": [
611612
"#| export\n",
612-
"def add_sub_reverse_proxy(domain, subdomain, ports, host='localhost'):\n",
613+
"def add_sub_reverse_proxy(\n",
614+
" domain,\n",
615+
" subdomain,\n",
616+
" port:str|int|Sequence[str|int], # A single port or list of ports\n",
617+
" host='localhost'\n",
618+
" ):\n",
613619
"\"Add a reverse proxy to a wildcard subdomain supporting multiple ports\"\n",
614620
" wildcard_id = f\"wildcard-{domain}\"\n",
615621
" route_id = f\"{subdomain}.{domain}\"\n",
616-
" if isinstance(ports, (int,str)):ports = [ports]\n",
617-
" upstreams = [{\"dial\": f\"{host}:{port}\"} forport inports]\n",
622+
" if isinstance(port, (int,str)):port = [port]\n",
623+
" upstreams = [{\"dial\": f\"{host}:{p}\"} forp inport]\n",
618624
" new_route = {\n",
619625
"\"@id\": route_id,\n",
620626
"\"match\": [{\"host\": [route_id]}],\n",
@@ -632,7 +638,7 @@
632638
"metadata": {},
633639
"outputs": [],
634640
"source": [
635-
"#add_sub_reverse_proxy('something.fast.ai', 'foo', 5001)"
641+
"add_sub_reverse_proxy('something.fast.ai', 'foo', 5001)"
636642
]
637643
},
638644
{
@@ -641,7 +647,7 @@
641647
"metadata": {},
642648
"outputs": [],
643649
"source": [
644-
"#del_id('foo.something.fast.ai')"
650+
"del_id('foo.something.fast.ai')"
645651
]
646652
},
647653
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp