Skip to content

Commit fbb3c67

Browse files
authored
Merge pull request #269 from gosuda/feature/relay-api-routing
Feature/relay api routing
2 parents c33e401 + 552fc4f commit fbb3c67

47 files changed

Lines changed: 429 additions & 400 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ portal expose --name myapp \
7272

7373
# Require x402 payment before a local HTTP upstream receives traffic
7474
portal expose 3000 --name paid-api \
75-
--x402-facilitator-url https://portal.example.com/x402 \
75+
--x402-facilitator-url https://portal.example.com/api/x402 \
7676
--x402-network eip155:8453 \
7777
--x402-price "$0.001"
7878

cmd/payment-app/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func run(args []string) error {
6363
utils.StringFlag(fs, &cfg.thumbnail, "thumbnail", defaultPhotoURL, "lease thumbnail")
6464
utils.StringFlag(fs, &cfg.photoURL, "photo-url", defaultPhotoURL, "image URL revealed after payment")
6565
utils.BoolFlag(fs, &cfg.hide, "hide", false, "hide this lease from listings")
66-
utils.StringFlag(fs, &cfg.x402.FacilitatorURL, "x402-facilitator-url", "https://gosunuts.xyz/x402", "x402 facilitator URL, such as https://relay.example.com:4017/x402")
66+
utils.StringFlag(fs, &cfg.x402.FacilitatorURL, "x402-facilitator-url", "https://gosunuts.xyz/api/x402", "x402 facilitator URL, such as https://relay.example.com:4017/api/x402")
6767
utils.StringFlag(fs, &cfg.x402.Network, "x402-network", "eip155:84532", "x402 payment network, such as eip155:8453")
6868
utils.StringFlag(fs, &cfg.x402.Price, "x402-price", "$0.001", "x402 price for the protected image, such as $0.01")
6969
utils.StringFlag(fs, &cfg.x402.PayTo, "x402-pay-to", "", "x402 recipient address; empty uses the payment app identity address")
@@ -182,7 +182,7 @@ func printUsage(w io.Writer) {
182182
[]string{
183183
"payment-app",
184184
"payment-app --name paid-photo",
185-
"payment-app --x402-facilitator-url https://relay.example.com:4017/x402 --x402-network eip155:8453 --x402-price \"$0.01\"",
185+
"payment-app --x402-facilitator-url https://relay.example.com:4017/api/x402 --x402-network eip155:8453 --x402-price \"$0.01\"",
186186
},
187187
)
188188
}

cmd/portal-tunnel/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ portal list
3535
If your relay publishes its own installer, use that relay instead:
3636

3737
```bash
38-
curl -sSL https://portal.example.com/install.sh | bash
38+
curl -sSL https://portal.example.com/api/install.sh | bash
3939
portal expose 3000 --relays https://portal.example.com --discovery=false
4040
```
4141

4242
```powershell
4343
$ProgressPreference = 'SilentlyContinue'
44-
irm https://portal.example.com/install.ps1 | iex
44+
irm https://portal.example.com/api/install.ps1 | iex
4545
portal expose 3000 --relays https://portal.example.com --discovery=false
4646
```
4747

@@ -78,7 +78,7 @@ app receives the request:
7878
```text
7979
portal expose 3000 --name paid-api \
8080
--description "Paid API" \
81-
--x402-facilitator-url https://portal.example.com:4017/x402 \
81+
--x402-facilitator-url https://portal.example.com:4017/api/x402 \
8282
--x402-network eip155:8453 \
8383
--x402-price "$0.001" \
8484
--x402-resource /
@@ -117,7 +117,7 @@ upstream = "http://127.0.0.1:3001"
117117
network = "eip155:8453"
118118
price = "$0.010"
119119
pay_to = "identity"
120-
facilitator_url = "https://portal.example.com:4017/x402"
120+
facilitator_url = "https://portal.example.com:4017/api/x402"
121121
resource = "/api/report"
122122
mime_type = "application/json"
123123

@@ -129,7 +129,7 @@ upstream = "http://127.0.0.1:3001"
129129
network = "eip155:8453"
130130
price = "$0.050"
131131
pay_to = "identity"
132-
facilitator_url = "https://portal.example.com:4017/x402"
132+
facilitator_url = "https://portal.example.com:4017/api/x402"
133133
resource = "/api/dataset"
134134
mime_type = "application/json"
135135
```
@@ -153,7 +153,7 @@ protected, err := portalx402.NewHTTPRouteHandler(portalx402.HTTPRouteHandlerConf
153153
`cmd/payment-app` includes this native x402 pattern. Run it with:
154154

155155
```text
156-
payment-app --x402-facilitator-url https://portal.example.com:4017/x402 \
156+
payment-app --x402-facilitator-url https://portal.example.com:4017/api/x402 \
157157
--x402-network eip155:8453 \
158158
--x402-price "$0.01"
159159
```
@@ -388,7 +388,7 @@ upstream = "http://127.0.0.1:3000"
388388
network = "eip155:8453"
389389
price = "$0.001"
390390
pay_to = "identity"
391-
facilitator_url = "https://portal.example.com:4017/x402"
391+
facilitator_url = "https://portal.example.com:4017/api/x402"
392392
resource = "/"
393393
```
394394

cmd/portal-tunnel/agent/dashboard.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func RunDashboard(configPath, stateDir string) error {
167167
metadataOwner: newAgentDashboardInlineInput("owner"),
168168
metadataThumbnail: newAgentDashboardInlineInput("https://..."),
169169
metadataHide: newAgentDashboardInlineInput("true or false"),
170-
x402FacilitatorURL: newAgentDashboardInlineInput("https://relay.example.com/x402"),
170+
x402FacilitatorURL: newAgentDashboardInlineInput("https://relay.example.com/api/x402"),
171171
}
172172
model.resizeInputs(0)
173173

cmd/portal-tunnel/installer/installer.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
_ "embed"
55
"errors"
66
"strings"
7+
8+
"github.com/gosuda/portal-tunnel/v2/types"
79
)
810

911
//go:embed install.sh
@@ -47,7 +49,7 @@ func relayShellScript(portalURL, script string) string {
4749
overrides := strings.Join([]string{
4850
"BASE_URL=" + quoteShellValue(portalURL),
4951
"RELAY_URL=" + quoteShellValue(portalURL),
50-
"BIN_PATH_PREFIX='install/bin'",
52+
"BIN_PATH_PREFIX=" + quoteShellValue(strings.Trim(types.PathInstallBinPrefix, "/")),
5153
"",
5254
}, "\n")
5355
return insertAfterShebang(script, overrides)
@@ -57,7 +59,7 @@ func relayPowerShellScript(portalURL, script string) string {
5759
overrides := strings.Join([]string{
5860
"$env:BASE_URL = " + quotePowerShellValue(portalURL),
5961
"$env:RELAY_URL = " + quotePowerShellValue(portalURL),
60-
"$env:BIN_PATH_PREFIX = 'install/bin'",
62+
"$env:BIN_PATH_PREFIX = " + quotePowerShellValue(strings.Trim(types.PathInstallBinPrefix, "/")),
6163
"",
6264
}, "\n")
6365
return overrides + script

cmd/portal-tunnel/installer/update.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import (
1414
"strings"
1515
"time"
1616

17+
"golang.org/x/mod/semver"
18+
1719
"github.com/gosuda/portal-tunnel/v2/types"
1820
"github.com/gosuda/portal-tunnel/v2/utils"
1921
)
@@ -48,7 +50,12 @@ func StartUpdateCheck(currentVersion string) {
4850
segments := strings.Split(strings.TrimPrefix(parsed.Path, "/"), "/")
4951
if len(segments) >= 5 {
5052
version := segments[4]
51-
if strings.HasPrefix(version, "v") && version != currentVersion {
53+
current := strings.TrimSpace(currentVersion)
54+
if current != "" && !strings.HasPrefix(current, "v") {
55+
current = "v" + current
56+
}
57+
latestValid := strings.HasPrefix(version, "v") && semver.IsValid(version)
58+
if latestValid && semver.IsValid(current) && semver.Compare(version, current) > 0 {
5259
fmt.Fprintf(os.Stderr, "\nA new version is available: %s. Run 'portal update' to upgrade.\n", version)
5360
}
5461
}

cmd/relay-server/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func (api *RelayAPI) serveAdmin(w http.ResponseWriter, r *http.Request) {
171171
}
172172

173173
switch path {
174-
case "/admin/metrics":
174+
case types.PathAdmin + "/metrics":
175175
promhttp.Handler().ServeHTTP(w, r)
176176
return
177177
default:

cmd/relay-server/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func runServeCommand(args []string) error {
9393
utils.StringFlagEnv(fs, &cfg.AdminWallets, "admin-wallets", "", "admin wallet address allowlist, comma-separated; relay identity address is always allowed", "ADMIN_WALLETS")
9494
utils.BoolFlagEnv(fs, &cfg.PProfEnabled, "pprof-enabled", false, "enable pprof diagnostics HTTP server", "PPROF_ENABLED")
9595
utils.StringFlagEnv(fs, &cfg.PProfAddr, "pprof-addr", portal.DefaultPProfListenAddr, "pprof diagnostics listen address when enabled", "PPROF_ADDR")
96-
utils.BoolFlagEnv(fs, &cfg.X402Enabled, "x402-facilitator-enabled", false, "enable relay-local x402 facilitator endpoints under /x402", "X402_FACILITATOR_ENABLED")
96+
utils.BoolFlagEnv(fs, &cfg.X402Enabled, "x402-facilitator-enabled", false, "enable relay-local x402 facilitator endpoints under /api/x402", "X402_FACILITATOR_ENABLED")
9797
utils.StringFlagEnv(fs, &cfg.X402Network, "x402-network", "", "x402 facilitator CAIP-2 network, such as eip155:8453", "X402_NETWORK")
9898
utils.StringFlagEnv(fs, &cfg.X402RPCURL, "x402-rpc-url", "", "x402 facilitator RPC URL; empty uses the PublicNode default for supported networks", "X402_RPC_URL")
9999

config.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
# Bump protocol versions only when wire-level behavior changes.
33

44
[release]
5-
version = "v2.2.5"
5+
version = "v2.3.0"
66
base_url = "https://github.com/gosuda/portal-tunnel/releases"
77

88
[protocol]
9-
tunnel = "7"
10-
discovery = "7"
9+
tunnel = "8"
10+
discovery = "8"

docker-compose.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ services:
4444
# restart: unless-stopped
4545

4646
portal-api:
47-
image: ghcr.io/gosuda/portal-api:latest
47+
image: ghcr.io/gosuda/portal-api:2
4848
build:
4949
context: ./frontend
5050
dockerfile: Dockerfile
@@ -66,7 +66,7 @@ services:
6666
restart: unless-stopped
6767

6868
portal-frontend:
69-
image: ghcr.io/gosuda/portal-frontend:latest
69+
image: ghcr.io/gosuda/portal-frontend:2
7070
build:
7171
context: ./frontend
7272
dockerfile: Dockerfile
@@ -76,7 +76,7 @@ services:
7676
restart: unless-stopped
7777

7878
portal:
79-
image: ghcr.io/gosuda/portal:latest
79+
image: ghcr.io/gosuda/portal:2
8080
build:
8181
context: .
8282
dockerfile: Dockerfile
@@ -111,7 +111,7 @@ services:
111111
TRUST_PROXY_HEADERS: ${TRUST_PROXY_HEADERS:-true}
112112
TRUSTED_PROXY_CIDRS: ${TRUSTED_PROXY_CIDRS:-}
113113

114-
# Optional: relay-local x402 facilitator exposed under /x402
114+
# Optional: relay-local x402 facilitator exposed under /api/x402
115115
X402_FACILITATOR_ENABLED: ${X402_FACILITATOR_ENABLED:-false}
116116
X402_NETWORK: ${X402_NETWORK:-eip155:84532}
117117
X402_RPC_URL: ${X402_RPC_URL:-https://base-sepolia-rpc.publicnode.com}

0 commit comments

Comments
 (0)