@cryptotaxi247 / kubo / commits / deab971dd

Use gateway URL when linking to another CID root

This is necessary to support subdomain resolution. E.g. {cid}.ipfs.localhost

Kevin Neaton committed Jul 17, 2020 at 22:42 UTC deab971dd03db6cf9609d312c6fdb414d58f4c69
2 files changed +5 -2
dir-index.html
+3 -2
@@ -1,4 +1,5 @@
1 <!DOCTYPE html>
2 +{{ $root := . }}
3 <html>
4 <head>
5 <meta charset="utf-8" />
@@ -44,7 +45,7 @@
45 <strong>
46 Index of
47 {{ range .Breadcrumbs -}}
47 - /{{ if .Path }}<a href="{{ .Path | urlEscape }}">{{ .Name }}</a>{{ else }}{{ .Name }}{{ end }}
48 + /{{ if .Path }}<a href="{{ $root.GatewayURL }}{{ .Path | urlEscape }}">{{ .Name }}</a>{{ else }}{{ .Name }}{{ end }}
49 {{- else }}
50 {{ .Path }}
51 {{ end }}
@@ -83,7 +84,7 @@
84 </td>
85 <td class="no-linebreak">
86 {{ if .Hash }}
86 - <a href="/ipfs/{{ .Hash | urlEscape }}">
87 + <a href="{{ $root.GatewayURL }}/ipfs/{{ .Hash | urlEscape }}">
88 {{ .ShortHash }}
89 </a>
90 {{ end }}
test/main.go
+2
@@ -12,6 +12,7 @@ const templateFile = "../dir-index.html"
12
13 // Copied from go-ipfs/core/corehttp/gateway_indexPage.go
14 type listingTemplateData struct {
15 + GatewayURL string
16 Listing []directoryItem
17 Size string
18 Path string
@@ -35,6 +36,7 @@ type breadcrumb struct {
36
37 var testPath = "/ipfs/QmFooBarQXB2mzChmMeKY47C43LxUdg1NDJ5MWcKMKxDu7/a/b/c"
38 var testData = listingTemplateData{
39 + GatewayURL: "//localhost:3000",
40 Listing: []directoryItem{{
41 Size: "25 MiB",
42 Name: "short-film.mov",