Skip to content

Commit 898bbf8

Browse files
authored
Merge pull request #32 from aniongithub/fix/tls-service-path
fix: derive TLS path from wiki dir for service compatibility
2 parents 69fd15d + 985a8b3 commit 898bbf8

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

cmd/mind-map/main.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,10 @@ func runHTTPServer(addr, dir, webuiDir string, idleTimeout time.Duration, stopCh
394394
IdleTimeout: idleTimeout,
395395
}
396396

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

401403
if useTLS {

cmd/mind-map/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ var serviceStartCmd = &cobra.Command{
172172
}
173173
fmt.Println("Service started.")
174174
scheme := "http"
175-
if mindtls.HasCerts(mindtls.DefaultDir()) {
175+
if mindtls.HasCerts(mindtls.DirFromWikiDir(dir)) {
176176
scheme = "https"
177177
}
178178
fmt.Printf(" Web UI: %s://%s\n", scheme, addr)

internal/tls/tls.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ func DefaultDir() string {
3434
return filepath.Join(home, ".mind-map", "tls")
3535
}
3636

37+
// DirFromWikiDir derives the TLS directory from the wiki directory.
38+
// The wiki dir is typically ~/.mind-map/wiki, so TLS is the sibling
39+
// ~/.mind-map/tls. This is more reliable than DefaultDir() when
40+
// running as a system service (where os.UserHomeDir() may differ).
41+
func DirFromWikiDir(wikiDir string) string {
42+
return filepath.Join(filepath.Dir(wikiDir), "tls")
43+
}
44+
3745
// CertPaths returns the paths to the server cert and key.
3846
func CertPaths(dir string) (certFile, keyFile string) {
3947
return filepath.Join(dir, "server.crt"), filepath.Join(dir, "server.key")

0 commit comments

Comments
 (0)