|
34 | 34 | "#| export\n", |
35 | 35 | "import os, subprocess, httpx, json\n", |
36 | 36 | "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" |
38 | 39 | ] |
39 | 40 | }, |
40 | 41 | { |
|
599 | 600 | "metadata": {}, |
600 | 601 | "outputs": [], |
601 | 602 | "source": [ |
602 | | -"#add_wildcard_route('something.fast.ai')" |
| 603 | +"add_wildcard_route('something.fast.ai')" |
603 | 604 | ] |
604 | 605 | }, |
605 | 606 | { |
|
609 | 610 | "outputs": [], |
610 | 611 | "source": [ |
611 | 612 | "#| 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", |
614 | 620 | " wildcard_id = f\"wildcard-{domain}\"\n", |
615 | 621 | " 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", |
616 | 624 | " new_route = {\n", |
617 | 625 | "\"@id\": route_id,\n", |
618 | 626 | "\"match\": [{\"host\": [route_id]}],\n", |
619 | 627 | "\"handle\": [{\n", |
620 | 628 | "\"handler\":\"reverse_proxy\",\n", |
621 | | -"\"upstreams\":[{\"dial\": f\"{host}:{port}\"}]\n", |
| 629 | +"\"upstreams\":upstreams\n", |
622 | 630 | " }]\n", |
623 | 631 | " }\n", |
624 | 632 | " pid([new_route], f\"{wildcard_id}/handle/0/routes/...\")" |
|
630 | 638 | "metadata": {}, |
631 | 639 | "outputs": [], |
632 | 640 | "source": [ |
633 | | -"#add_sub_reverse_proxy('something.fast.ai', 'foo', 5001)" |
| 641 | +"add_sub_reverse_proxy('something.fast.ai', 'foo', 5001)" |
634 | 642 | ] |
635 | 643 | }, |
636 | 644 | { |
|
639 | 647 | "metadata": {}, |
640 | 648 | "outputs": [], |
641 | 649 | "source": [ |
642 | | -"#del_id('foo.something.fast.ai')" |
| 650 | +"del_id('foo.something.fast.ai')" |
643 | 651 | ] |
644 | 652 | }, |
645 | 653 | { |
|