Skip to content

Commit

Permalink
Merge pull request #6 from SiaFoundation/nate/gateway-configure-redir…
Browse files Browse the repository at this point in the history
…ects

Configure gateway redirects
  • Loading branch information
n8maninger authored Nov 21, 2023
2 parents 57198e2 + 5e10dcf commit 2d7de98
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
6 changes: 4 additions & 2 deletions cmd/fsd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ var (
Bucket: "ipfs",
},
IPFS: config.IPFS{
GatewayAddress: ":8080",
Gateway: config.HTTPGateway{
ListenAddress: ":8080",
},
},
API: config.API{
Address: ":8081",
Expand Down Expand Up @@ -164,7 +166,7 @@ func main() {
}
defer apiListener.Close()

gatewayListener, err := net.Listen("tcp", cfg.IPFS.GatewayAddress)
gatewayListener, err := net.Listen("tcp", cfg.IPFS.Gateway.ListenAddress)
if err != nil {
log.Fatal("failed to listen", zap.Error(err))
}
Expand Down
18 changes: 12 additions & 6 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ type (
Bucket string `yaml:"bucket"`
}

// IPFS contains the listen address of the IPFS gateway
// HTTPGateway contains the configuration for the IPFS HTTP gateway
HTTPGateway struct {
ListenAddress string `yaml:"ListenAddress"`
RedirectPathStyle bool `yaml:"redirectPathStyle"`
}

// IPFS contains the configuration for the IPFS node
IPFS struct {
PrivateKey string `yaml:"privateKey"`
GatewayAddress string `yaml:"gatewayAddress"`
ListenAddresses []string `yaml:"listenAddresses"`
AnnounceAddresses []string `yaml:"announceAddresses"`
FetchRemote bool `yaml:"fetchRemote"`
PrivateKey string `yaml:"privateKey"`
ListenAddresses []string `yaml:"listenAddresses"`
AnnounceAddresses []string `yaml:"announceAddresses"`
FetchRemote bool `yaml:"fetchRemote"`
Gateway HTTPGateway `yaml:"gateway"`
}

// API contains the listen address of the API server
Expand Down
2 changes: 1 addition & 1 deletion http/ipfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (is *ipfsGatewayServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
redirect = true
}

if redirect {
if redirect && is.config.IPFS.Gateway.RedirectPathStyle {
redirectPathCID(w, r, c, path, is.log.Named("redirect"))
return
}
Expand Down

0 comments on commit 2d7de98

Please sign in to comment.