Skip to content

Commit acd4e31

Browse files
committed
feat: add -b/--bind flag to proxy command
1 parent 7962180 commit acd4e31

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,15 @@ tinfoil proxy \
296296
-p 8080
297297
```
298298

299+
### Command Options
300+
301+
- `-p, --port`: Port to listen on. Defaults to `8080`.
302+
- `-b, --bind`: Address to bind to. Defaults to `127.0.0.1`.
303+
- `-e, --host`: The hostname of the enclave.
304+
- `-r, --repo`: The GitHub repository containing code measurements.
305+
306+
By default, the proxy binds to `127.0.0.1` (localhost only). To expose the proxy on all interfaces, use `-b 0.0.0.0`.
307+
299308
## Docker
300309

301310
A docker image is available at `ghcr.io/tinfoilsh/tinfoil-cli`.

proxy.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package main
22

33
import (
4-
"fmt"
54
"io"
5+
"net"
66
"net/http"
77
"net/url"
8+
"strconv"
89

910
log "github.com/sirupsen/logrus"
1011
"github.com/spf13/cobra"
@@ -13,11 +14,13 @@ import (
1314

1415
var (
1516
listenPort uint
17+
listenAddr string
1618
)
1719

1820
func init() {
1921
rootCmd.AddCommand(proxyCmd)
2022
proxyCmd.Flags().UintVarP(&listenPort, "port", "p", 8080, "Port to listen on")
23+
proxyCmd.Flags().StringVarP(&listenAddr, "bind", "b", "127.0.0.1", "Address to bind to")
2124
}
2225

2326
var proxyCmd = &cobra.Command{
@@ -69,7 +72,8 @@ var proxyCmd = &cobra.Command{
6972
}
7073
})
7174

72-
log.Infof("Starting HTTP proxy on %d", listenPort)
73-
return http.ListenAndServe(fmt.Sprintf(":%d", listenPort), nil)
75+
addr := net.JoinHostPort(listenAddr, strconv.FormatUint(uint64(listenPort), 10))
76+
log.Infof("Starting HTTP proxy on %s", addr)
77+
return http.ListenAndServe(addr, nil)
7478
},
7579
}

0 commit comments

Comments
 (0)