Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions cmd/mind-map/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,10 @@ func runHTTPServer(addr, dir, webuiDir string, idleTimeout time.Duration, stopCh
IdleTimeout: idleTimeout,
}

// Serve HTTPS if TLS certs are available, otherwise HTTP
tlsDir := mindtls.DefaultDir()
// Serve HTTPS if TLS certs are available, otherwise HTTP.
// Derive TLS dir from the wiki dir (sibling directory) so it works
// correctly when running as a system service with a different home.
tlsDir := mindtls.DirFromWikiDir(dir)
useTLS := mindtls.HasCerts(tlsDir)

if useTLS {
Expand Down
2 changes: 1 addition & 1 deletion cmd/mind-map/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ var serviceStartCmd = &cobra.Command{
}
fmt.Println("Service started.")
scheme := "http"
if mindtls.HasCerts(mindtls.DefaultDir()) {
if mindtls.HasCerts(mindtls.DirFromWikiDir(dir)) {
scheme = "https"
}
fmt.Printf(" Web UI: %s://%s\n", scheme, addr)
Expand Down
8 changes: 8 additions & 0 deletions internal/tls/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ func DefaultDir() string {
return filepath.Join(home, ".mind-map", "tls")
}

// DirFromWikiDir derives the TLS directory from the wiki directory.
// The wiki dir is typically ~/.mind-map/wiki, so TLS is the sibling
// ~/.mind-map/tls. This is more reliable than DefaultDir() when
// running as a system service (where os.UserHomeDir() may differ).
func DirFromWikiDir(wikiDir string) string {
return filepath.Join(filepath.Dir(wikiDir), "tls")
}

// CertPaths returns the paths to the server cert and key.
func CertPaths(dir string) (certFile, keyFile string) {
return filepath.Join(dir, "server.crt"), filepath.Join(dir, "server.key")
Expand Down