Skip to content

Commit c091fd6

Browse files
committed
feat: migrate subdomain and dnslink code
1 parent 302b279 commit c091fd6

File tree

8 files changed

+1022
-8
lines changed

8 files changed

+1022
-8
lines changed

examples/gateway-car/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Then, you can start the gateway with:
2626
./gateway -c data.car -p 8040
2727
```
2828

29-
Now you can access the gateway in [127.0.0.1:8040](http://127.0.0.1:8040). It will
29+
Now you can access the gateway in [localhost:8040](http://localhost:8040). It will
3030
behave like a regular IPFS Gateway, except for the fact that all contents are provided
3131
from the CAR file. Therefore, things such as IPNS resolution and fetching contents
3232
from nodes in the IPFS network won't work.

examples/gateway-car/main.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,33 @@ func main() {
2626
}
2727
defer f.Close()
2828

29-
gateway, err := newBlocksGateway(blockService)
29+
gwAPI, err := newBlocksGateway(blockService)
3030
if err != nil {
3131
log.Fatal(err)
3232
}
3333

34-
handler := newHandler(gateway, *portPtr)
34+
handler := newHandler(gwAPI, *portPtr)
3535

36-
address := "127.0.0.1:" + strconv.Itoa(*portPtr)
37-
log.Printf("Listening on http://%s", address)
36+
// Initialize the public gateways that we will want to have available through
37+
// Host header rewritting. This step is optional and only required if you're
38+
// running multiple public gateways and want different settings and support
39+
// for DNSLink and Subdomain Gateways.
40+
publicGateways := map[string]*gateway.Specification{
41+
"localhost": {
42+
Paths: []string{"/ipfs", "/ipns"},
43+
NoDNSLink: true,
44+
UseSubdomains: true,
45+
},
46+
}
47+
noDNSLink := true
48+
handler = gateway.WithHostname(handler, gwAPI, publicGateways, noDNSLink)
49+
50+
log.Printf("Listening on http://localhost:%d", *portPtr)
3851
for _, cid := range roots {
39-
log.Printf("Hosting CAR root at http://%s/ipfs/%s", address, cid.String())
52+
log.Printf("Hosting CAR root at http://localhost:%d/ipfs/%s", *portPtr, cid.String())
4053
}
4154

42-
if err := http.ListenAndServe(address, handler); err != nil {
55+
if err := http.ListenAndServe(":"+strconv.Itoa(*portPtr), handler); err != nil {
4356
log.Fatal(err)
4457
}
4558
}

examples/go.mod

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ require (
3535
github.com/go-logr/stdr v1.2.2 // indirect
3636
github.com/gogo/protobuf v1.3.2 // indirect
3737
github.com/golang/protobuf v1.5.2 // indirect
38+
github.com/google/gopacket v1.1.19 // indirect
3839
github.com/google/uuid v1.3.0 // indirect
40+
github.com/hashicorp/errwrap v1.1.0 // indirect
41+
github.com/hashicorp/go-multierror v1.1.1 // indirect
3942
github.com/hashicorp/golang-lru v0.5.4 // indirect
4043
github.com/ipfs/bbloom v0.0.4 // indirect
4144
github.com/ipfs/go-bitfield v1.0.0 // indirect
@@ -52,21 +55,31 @@ require (
5255
github.com/ipfs/go-log v1.0.5 // indirect
5356
github.com/ipfs/go-log/v2 v2.5.1 // indirect
5457
github.com/ipfs/go-metrics-interface v0.0.1 // indirect
58+
github.com/ipfs/go-namesys v0.7.0 // indirect
5559
github.com/ipfs/go-verifcid v0.0.2 // indirect
5660
github.com/ipld/go-car v0.5.0 // indirect
5761
github.com/jbenet/goprocess v0.1.4 // indirect
5862
github.com/klauspost/cpuid/v2 v2.2.3 // indirect
5963
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
64+
github.com/libp2p/go-cidranger v1.1.0 // indirect
6065
github.com/libp2p/go-libp2p v0.23.4 // indirect
66+
github.com/libp2p/go-libp2p-asn-util v0.2.0 // indirect
67+
github.com/libp2p/go-libp2p-kad-dht v0.19.0 // indirect
68+
github.com/libp2p/go-libp2p-kbucket v0.5.0 // indirect
69+
github.com/libp2p/go-libp2p-record v0.2.0 // indirect
70+
github.com/libp2p/go-msgio v0.2.0 // indirect
71+
github.com/libp2p/go-netroute v0.2.0 // indirect
6172
github.com/libp2p/go-openssl v0.1.0 // indirect
6273
github.com/mattn/go-isatty v0.0.17 // indirect
6374
github.com/mattn/go-pointer v0.0.1 // indirect
6475
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
76+
github.com/miekg/dns v1.1.50 // indirect
6577
github.com/minio/sha256-simd v1.0.0 // indirect
6678
github.com/mr-tron/base58 v1.2.0 // indirect
6779
github.com/multiformats/go-base32 v0.1.0 // indirect
6880
github.com/multiformats/go-base36 v0.2.0 // indirect
6981
github.com/multiformats/go-multiaddr v0.8.0 // indirect
82+
github.com/multiformats/go-multiaddr-dns v0.3.1 // indirect
7083
github.com/multiformats/go-multibase v0.1.1 // indirect
7184
github.com/multiformats/go-multicodec v0.7.0 // indirect
7285
github.com/multiformats/go-multihash v0.2.1 // indirect
@@ -83,18 +96,23 @@ require (
8396
github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 // indirect
8497
github.com/spaolacci/murmur3 v1.1.0 // indirect
8598
github.com/ucarion/urlpath v0.0.0-20200424170820-7ccc79b76bbb // indirect
99+
github.com/whyrusleeping/base32 v0.0.0-20170828182744-c30ac30633cc // indirect
86100
github.com/whyrusleeping/cbor v0.0.0-20171005072247-63513f603b11 // indirect
87101
github.com/whyrusleeping/cbor-gen v0.0.0-20230126041949-52956bd4c9aa // indirect
102+
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 // indirect
103+
go.opencensus.io v0.23.0 // indirect
88104
go.opentelemetry.io/otel v1.12.0 // indirect
89105
go.opentelemetry.io/otel/trace v1.12.0 // indirect
90106
go.uber.org/atomic v1.10.0 // indirect
91107
go.uber.org/multierr v1.9.0 // indirect
92108
go.uber.org/zap v1.24.0 // indirect
93109
golang.org/x/crypto v0.5.0 // indirect
94110
golang.org/x/exp v0.0.0-20230129154200-a960b3787bd2 // indirect
111+
golang.org/x/mod v0.6.0 // indirect
95112
golang.org/x/net v0.5.0 // indirect
96113
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
97114
golang.org/x/sys v0.4.0 // indirect
115+
golang.org/x/tools v0.2.0 // indirect
98116
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
99117
google.golang.org/protobuf v1.28.1 // indirect
100118
gopkg.in/yaml.v3 v3.0.1 // indirect

0 commit comments

Comments
 (0)