6
1
mirror of https://git.mills.io/saltyim/saltyim.git synced 2024-07-03 00:33:38 +00:00
prologic-saltyim/internal/handlers.go
James Mills be4b4a5e9d Add a basic structure for a go-app PWA + integrated Broker (#36)
Co-authored-by: James Mills <prologic@shortcircuit.net.au>
Co-authored-by: Jon Lundy <jon@xuu.cc>
Reviewed-on: https://git.mills.io/prologic/saltyim/pulls/36
2022-03-21 22:27:35 +00:00

38 lines
976 B
Go

package internal
import (
"net/http"
"git.mills.io/prologic/useragent"
"github.com/julienschmidt/httprouter"
)
func (s *Server) NotFoundHandler(w http.ResponseWriter, r *http.Request) {
if r.Header.Get("Accept") == "application/json" {
w.Header().Set("Content-Type", "application/json")
http.Error(w, "Endpoint Not Found", http.StatusNotFound)
return
}
w.WriteHeader(http.StatusNotFound)
w.Write([]byte("404 Not Found"))
}
// IndexHandler ...
func (s *Server) IndexHandler() httprouter.Handle {
return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
ua := useragent.Parse(r.UserAgent())
if ua != nil && ua.Type == useragent.Browser {
http.Redirect(w, r, "/app/", http.StatusFound)
}
}
}
// InboxHandler ...
func (s *Server) InboxHandler() httprouter.Handle {
return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
// TODO: Implement filtering / blocking at the broker level
s.bus.ServeHTTP(w, r)
}
}