2022-06-06 16:48:53 +00:00
|
|
|
package handler
|
|
|
|
|
|
|
|
import (
|
|
|
|
_ "embed"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
//go:embed static/index.html
|
|
|
|
var indexPage string
|
|
|
|
|
|
|
|
func New(matrixHostname, matrixBaseURL string) http.HandlerFunc {
|
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if r.Method != http.MethodGet {
|
2022-06-06 18:23:49 +00:00
|
|
|
w.WriteHeader(http.StatusMethodNotAllowed)
|
|
|
|
w.Write([]byte("405 method not allowed\n"))
|
2022-06-06 16:48:53 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
switch r.URL.Path {
|
|
|
|
case "/.well-known/matrix/server":
|
|
|
|
w.Header().Add("content-type", "application/json")
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
|
w.Write([]byte(`{"m.server": "` + matrixHostname + `"}`))
|
|
|
|
case "/.well-known/matrix/client":
|
|
|
|
w.Header().Add("content-type", "application/json")
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
|
w.Write([]byte(`{"m.homeserver": {"base_url": "` + matrixBaseURL + `"}}`))
|
2022-06-06 18:23:49 +00:00
|
|
|
case "/":
|
2022-06-06 16:48:53 +00:00
|
|
|
w.Header().Add("content-type", "text/html")
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
|
w.Write([]byte(indexPage))
|
2022-06-06 18:23:49 +00:00
|
|
|
default:
|
|
|
|
http.NotFound(w, r)
|
2022-06-06 16:48:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|