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

Commitd3caeea

Browse files
authored
Merge pull request#3 from AnswerDotAI/handle-multiport-sub-reverse-proxy
Modify add_sub_reverse_proxy to be multi-port
2 parents51fb056 +be2e929 commitd3caeea

File tree

3 files changed

+623
-10
lines changed

3 files changed

+623
-10
lines changed

‎fastcaddy/core.py‎

Lines changed: 11 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,16 +178,23 @@ def add_wildcard_route(domain):
177178
add_route(route)
178179

179180
# %% ../nbs/00_core.ipynb 48
180-
defadd_sub_reverse_proxy(domain,subdomain,port,host='localhost'):
181-
"Add a reverse proxy to a wildcard subdomain"
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+
):
187+
"Add a reverse proxy to a wildcard subdomain supporting multiple ports"
182188
wildcard_id=f"wildcard-{domain}"
183189
route_id=f"{subdomain}.{domain}"
190+
ifisinstance(port, (int,str)):port= [port]
191+
upstreams= [{"dial":f"{host}:{p}"}forpinport]
184192
new_route= {
185193
"@id":route_id,
186194
"match": [{"host": [route_id]}],
187195
"handle": [{
188196
"handler":"reverse_proxy",
189-
"upstreams":[{"dial":f"{host}:{port}"}]
197+
"upstreams":upstreams
190198
}]
191199
}
192200
pid([new_route],f"{wildcard_id}/handle/0/routes/...")

‎nbs/00_core.ipynb‎

Lines changed: 15 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,16 +610,23 @@
609610
"outputs": [],
610611
"source": [
611612
"#| export\n",
612-
"def add_sub_reverse_proxy(domain, subdomain, port, host='localhost'):\n",
613-
"\"Add a reverse proxy to a wildcard subdomain\"\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",
619+
"\"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",
622+
" if isinstance(port, (int,str)): port = [port]\n",
623+
" upstreams = [{\"dial\": f\"{host}:{p}\"} for p in port]\n",
616624
" new_route = {\n",
617625
"\"@id\": route_id,\n",
618626
"\"match\": [{\"host\": [route_id]}],\n",
619627
"\"handle\": [{\n",
620628
"\"handler\":\"reverse_proxy\",\n",
621-
"\"upstreams\":[{\"dial\": f\"{host}:{port}\"}]\n",
629+
"\"upstreams\":upstreams\n",
622630
" }]\n",
623631
" }\n",
624632
" pid([new_route], f\"{wildcard_id}/handle/0/routes/...\")"
@@ -630,7 +638,7 @@
630638
"metadata": {},
631639
"outputs": [],
632640
"source": [
633-
"#add_sub_reverse_proxy('something.fast.ai', 'foo', 5001)"
641+
"add_sub_reverse_proxy('something.fast.ai', 'foo', 5001)"
634642
]
635643
},
636644
{
@@ -639,7 +647,7 @@
639647
"metadata": {},
640648
"outputs": [],
641649
"source": [
642-
"#del_id('foo.something.fast.ai')"
650+
"del_id('foo.something.fast.ai')"
643651
]
644652
},
645653
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp