44 lines
909 B
Go
44 lines
909 B
Go
package main
|
|
|
|
import (
|
|
"converge/pkg/templates"
|
|
"net/http"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
func pageHandler(w http.ResponseWriter, r *http.Request) {
|
|
secure := ""
|
|
if r.TLS == nil {
|
|
secure = ""
|
|
} else {
|
|
secure = "s"
|
|
}
|
|
for _, header := range []string{"X-Forwarded-Proto", "X-Scheme", "X-Forwarded-Scheme"} {
|
|
values := r.Header.Values(header)
|
|
for _, value := range values {
|
|
if strings.ToLower(value) == "https" {
|
|
secure = "s"
|
|
}
|
|
}
|
|
}
|
|
username, _ := os.LookupEnv("CONVERGE_USERNAME")
|
|
|
|
switch r.URL.Path {
|
|
case "":
|
|
fallthrough
|
|
case "/":
|
|
fallthrough
|
|
case "index.html":
|
|
templates.AboutTab().Render(r.Context(), w)
|
|
case "usage.html":
|
|
templates.UsageTab(secure, r.URL.Host, username).Render(r.Context(), w)
|
|
case "downloads.html":
|
|
templates.DownloadsTab().Render(r.Context(), w)
|
|
case "sessions.html":
|
|
templates.SessionsTab().Render(r.Context(), w)
|
|
default:
|
|
http.NotFound(w, r)
|
|
}
|
|
}
|