-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserve.go
More file actions
51 lines (45 loc) · 1.36 KB
/
Copy pathserve.go
File metadata and controls
51 lines (45 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"log"
"net/http"
"os"
"path/filepath"
"time"
"code-mind/internal/appdata"
"code-mind/internal/server"
"code-mind/internal/store"
)
// runServe starts the headless HTTP server (formerly cmd/server). It shares
// the same data directory, token store, and permission model as the GUI.
func runServe() {
port := os.Getenv("CODE_MIND_PORT")
if port == "" {
port = "7979"
}
dataDir, err := appdata.ResolveDataDir()
if err != nil {
log.Fatal("failed to resolve data directory:", err)
}
dataPath := filepath.Join(dataDir, "maps")
fileStore := store.NewFileStore(dataPath)
settingsDir := filepath.Dir(dataPath)
tokenStore, err := store.NewTokenStore(filepath.Join(settingsDir, "tokens.json"))
if err != nil {
log.Fatal("failed to open token store:", err)
}
appServer := server.NewWithTokenStore(fileStore, settingsDir, tokenStore)
log.Printf("Code Mind server listening on http://localhost:%s", port)
srv := &http.Server{
Addr: ":" + port,
Handler: appServer.Handler(),
ReadHeaderTimeout: 10 * time.Second,
ReadTimeout: 2 * time.Minute,
// AI proxy requests can legitimately take up to the configured AI
// timeout (max 600s), so the write timeout must stay above that.
WriteTimeout: 11 * time.Minute,
IdleTimeout: 2 * time.Minute,
}
if err := srv.ListenAndServe(); err != nil {
log.Fatal(err)
}
}