mirror of
https://git.mills.io/saltyim/saltyim.git
synced 2024-06-30 18:51:03 +00:00
55d0fe7d51
Co-authored-by: James Mills <prologic@shortcircuit.net.au> Reviewed-on: https://git.mills.io/saltyim/saltyim/pulls/60
47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
package internal
|
|
|
|
import (
|
|
"net/http"
|
|
"path/filepath"
|
|
|
|
"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"))
|
|
}
|
|
|
|
// ConfigHandler ...
|
|
func (s *Server) ConfigHandler() httprouter.Handle {
|
|
configDir := filepath.Join(s.config.Data, wellknownPath)
|
|
return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
|
|
http.ServeFile(w, r, filepath.Join(configDir, p.ByName("config")))
|
|
}
|
|
}
|
|
|
|
// 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)
|
|
}
|
|
}
|