From 87f5fd1dafc06fa030ae634a2f066db2ae813176 Mon Sep 17 00:00:00 2001
From: Coogan
Date: Fri, 12 Jan 2018 12:27:50 -0600
Subject: [PATCH] swarm: now able to serve landing page template
---
swarm/api/http/server.go | 13 +++-
swarm/api/http/templates.go | 129 ++++++++++++++++++++++++++++++++++++
2 files changed, 141 insertions(+), 1 deletion(-)
diff --git a/swarm/api/http/server.go b/swarm/api/http/server.go
index 686f1cacd2..e1912d0150 100644
--- a/swarm/api/http/server.go
+++ b/swarm/api/http/server.go
@@ -554,7 +554,7 @@ func (s *Server) HandleGetFile(w http.ResponseWriter, r *Request) {
// create the landing page
// !! need to serve home node template page !!
-
+
// return the whole response
return
@@ -609,6 +609,15 @@ func (s *Server) HandleGetFile(w http.ResponseWriter, r *Request) {
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
s.logDebug("HTTP %s request URL: '%s', Host: '%s', Path: '%s', Referer: '%s', Accept: '%s'", r.Method, r.RequestURI, r.URL.Host, r.URL.Path, r.Referer(), r.Header.Get("Accept"))
+ if r.RequestURI == "/" && strings.Contains(r.Header.Get("Accept"), "text/html") {
+
+ err := landingPageTemplate.Execute(w, nil)
+ if err != nil {
+ s.logError("error rendering landing page: %s", err)
+ }
+ return
+ }
+
uri, err := api.Parse(strings.TrimLeft(r.URL.Path, "/"))
req := &Request{Request: *r, uri: uri}
if err != nil {
@@ -662,6 +671,8 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
+
+
s.HandleGetFile(w, req)
default:
diff --git a/swarm/api/http/templates.go b/swarm/api/http/templates.go
index 53ce7b5a22..66b62f2ad3 100644
--- a/swarm/api/http/templates.go
+++ b/swarm/api/http/templates.go
@@ -69,3 +69,132 @@ var htmlListTemplate = template.Must(template.New("html-list").Funcs(template.Fu
+
+
+
+
+
Welcome to Swarm
+
+
+
+
+
+
+
+ |
+ Enter the hash or ENS of a swarm-hosted file below:
+ |
+
+
+
+
+
+
+
+
+
+
+
+
`[1:]))
+
+var landingPageTemplate = template.Must(template.New("landing-page").Parse(`
+
+