hswaw/site: fix catch-all, add robots.txt

Change-Id: I23db4e18185f029a094ea4f69ac0f469d3dd8a8e
Reviewed-on: https://gerrit.hackerspace.pl/c/hscloud/+/1405
Reviewed-by: informatic <informatic@hackerspace.pl>
diff --git a/hswaw/site/main.go b/hswaw/site/main.go
index a0872d8..ff01b2d 100644
--- a/hswaw/site/main.go
+++ b/hswaw/site/main.go
@@ -126,5 +126,6 @@
 	mux.HandleFunc("/spaceapi", s.handleSpaceAPI)
 	mux.HandleFunc("/events.json", s.handleJSONEvents)
 	mux.HandleFunc("/event/", s.handleEvent)
+	mux.HandleFunc("/robots.txt", s.handleRobotsTxt)
 	mux.HandleFunc("/", s.handleIndex)
 }
diff --git a/hswaw/site/views.go b/hswaw/site/views.go
index 6109a55..7483afc 100644
--- a/hswaw/site/views.go
+++ b/hswaw/site/views.go
@@ -56,6 +56,12 @@
 
 // handleIndex handles rendering the main page at /.
 func (s *service) handleIndex(w http.ResponseWriter, r *http.Request) {
+	// Necessary as "/" is a catch-all in net/http.
+	if r.URL.Path != "/" {
+		http.NotFound(w, r)
+		return
+	}
+
 	ctx := r.Context()
 
 	atStatus, atError := getAt(ctx)
@@ -68,6 +74,12 @@
 	})
 }
 
+func (s *service) handleRobotsTxt(w http.ResponseWriter, r *http.Request) {
+	// Allow everyone everywhere. We don't really host much on hackerspace.pl anyway.
+	fmt.Fprintf(w, "User-agent: *\n")
+	fmt.Fprintf(w, "Allow: /\n")
+}
+
 func (s *service) handleJSONEvents(w http.ResponseWriter, r *http.Request) {
 	w.Header().Set("Content-Type", "application/json")
 	json.NewEncoder(w).Encode(s.getEvents())