From 22fc6928d720e3cc1f090ce2891f553db1e076ab Mon Sep 17 00:00:00 2001
From: cooganb
Date: Mon, 26 Feb 2018 02:56:40 -0600
Subject: swarm: creates Swarm landing page for browser 'localhost:xxxx/' GET
request when running Swarm (#15926)
* swarm: began work on GetHandleFile method re: issue #155
* swarm: now able to serve landing page template
* swarm: added landing page template
* swarm: landing page has working input
* swarm: fixed CSS issue in template
* swarm: deleted extra lines
* swarm: deleted time header and made redirect a relative path
* swarm: removed code mistakenly left
---
swarm/api/http/server.go | 9 +++
swarm/api/http/templates.go | 143 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 152 insertions(+)
(limited to 'swarm/api/http')
diff --git a/swarm/api/http/server.go b/swarm/api/http/server.go
index 6ebfc8059..df90fd04f 100644
--- a/swarm/api/http/server.go
+++ b/swarm/api/http/server.go
@@ -660,6 +660,15 @@ 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 {
diff --git a/swarm/api/http/templates.go b/swarm/api/http/templates.go
index 189a99912..cd9d21289 100644
--- a/swarm/api/http/templates.go
+++ b/swarm/api/http/templates.go
@@ -70,3 +70,146 @@ 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("landingPage").Parse(`
+
+