This commit is contained in:
Lennart J. Kurzweg (Nx2)
2026-03-24 23:27:14 +01:00
parent f961440f13
commit 057ba02865
6 changed files with 260 additions and 68 deletions

17
main.go
View File

@@ -12,9 +12,12 @@ import (
"github.com/emersion/go-webdav/caldav"
"nxcaldav/internal/backend"
"nxcaldav/internal/extra"
"nxcaldav/internal/config"
)
func main() {
path := "config.yaml";
if len(os.Args) == 3 {
@@ -61,12 +64,14 @@ func main() {
}
}
// public ics access
prefix := cfg.Server.BasePath()
if strings.HasPrefix(r.URL.Path, prefix+"/public/") {
be.ServePublicICS(w, r)
return
}
// caldav access needs auth
user, password, ok := r.BasicAuth()
if !ok {
w.Header().Set("WWW-Authenticate", `Basic realm="CalDAV Server"`)
@@ -88,13 +93,12 @@ func main() {
return
}
log.Printf("%s %s (user: %s)", r.Method, r.URL.Path, user)
prefix = cfg.Server.BasePath()
log.Printf("[user: %s] %s %s ", user, r.Method, r.URL.Path)
principalPath := prefix + fmt.Sprintf("/%s/", user)
ctx := context.WithValue(r.Context(), "principal", principalPath)
if r.URL.Path == "/.well-known/caldav" || r.URL.Path == prefix+"/.well-known/caldav" {
// If we normalized the request, use the normalized host/scheme for the redirect
// If normalized request, use normalized host/scheme for redirect
if publicURL != nil && publicURL.Host != "" {
scheme := r.URL.Scheme
if scheme == "" {
@@ -109,7 +113,12 @@ func main() {
}
handler.ServeHTTP(w, r.WithContext(ctx))
// needed because color info is not RFC, so regex hack
if r.Method == "PROPFIND" {
extra.AddColorToCalendarPropfind(r, ctx, handler, w, be)
} else {
handler.ServeHTTP(w, r.WithContext(ctx))
}
})
fmt.Printf("Starting CalDAV server on %s...\n", cfg.Server.BindAddress)