forked from hswaw/hscloud
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>
This commit is contained in:
parent
9171451c53
commit
15b5bc1783
2 changed files with 13 additions and 0 deletions
|
@ -126,5 +126,6 @@ func (s *service) registerHTTP(mux *http.ServeMux) {
|
|||
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)
|
||||
}
|
||||
|
|
|
@ -56,6 +56,12 @@ func render(w http.ResponseWriter, t *template.Template, data interface{}) {
|
|||
|
||||
// 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) handleIndex(w http.ResponseWriter, r *http.Request) {
|
|||
})
|
||||
}
|
||||
|
||||
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())
|
||||
|
|
Loading…
Reference in a new issue