mirror of
https://git.mills.io/saltyim/saltyim.git
synced 2024-06-28 09:41:02 +00:00
![xuu](/assets/img/avatar_default.png)
Co-authored-by: xuu <me@sour.is> Reviewed-on: https://git.mills.io/saltyim/saltyim/pulls/109
49 lines
1.4 KiB
Go
49 lines
1.4 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) {
|
|
w.Header().Set("Accept-Encoding", "br, gzip, deflate")
|
|
w.Header().Set("X-Salty-Accept-Encoding", "br, gzip, deflate")
|
|
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)
|
|
}
|
|
}
|