implement auth and a simple admin-follows whitelist
Some checks failed
Go / build (push) Has been cancelled

This commit is contained in:
2025-09-07 19:08:29 +01:00
parent f5a8c094e4
commit 5edb7a3b09
27 changed files with 458 additions and 117 deletions

View File

@@ -4,8 +4,11 @@ import (
"context"
"fmt"
"net/http"
"strconv"
"strings"
"database.orly"
"lol.mleku.dev/chk"
"lol.mleku.dev/log"
"next.orly.dev/app/config"
"protocol.orly/publish"
@@ -39,3 +42,33 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
}
}
func (s *Server) ServiceURL(req *http.Request) (st string) {
host := req.Header.Get("X-Forwarded-Host")
if host == "" {
host = req.Host
}
proto := req.Header.Get("X-Forwarded-Proto")
if proto == "" {
if host == "localhost" {
proto = "ws"
} else if strings.Contains(host, ":") {
// has a port number
proto = "ws"
} else if _, err := strconv.Atoi(
strings.ReplaceAll(
host, ".",
"",
),
); chk.E(err) {
// it's a naked IP
proto = "ws"
} else {
proto = "wss"
}
} else if proto == "https" {
proto = "wss"
} else if proto == "http" {
proto = "ws"
}
return proto + "://" + host
}