forked from MatiasDesuu/ThinkDashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
91 lines (77 loc) · 3.39 KB
/
Copy pathmain.go
File metadata and controls
91 lines (77 loc) · 3.39 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package main
import (
"embed"
"io/fs"
"log"
"mime"
"net/http"
"os"
"path/filepath"
"github.com/gorilla/mux"
)
//go:embed static/* templates/*
var embeddedFiles embed.FS
func main() {
// Initialize MIME types
mime.AddExtensionType(".css", "text/css")
mime.AddExtensionType(".js", "application/javascript")
// Initialize the data store
store := NewStore()
// Initialize handlers
handlers := NewHandlers(store, embeddedFiles)
// Create router
r := mux.NewRouter()
// Routes
r.HandleFunc("/", handlers.Dashboard).Methods("GET")
r.HandleFunc("/config", handlers.Config).Methods("GET")
r.HandleFunc("/colors", handlers.Colors).Methods("GET")
r.HandleFunc("/api/bookmarks", handlers.GetBookmarks).Methods("GET")
r.HandleFunc("/api/bookmarks", handlers.SaveBookmarks).Methods("POST")
r.HandleFunc("/api/bookmarks", handlers.DeleteBookmark).Methods("DELETE")
r.HandleFunc("/api/bookmarks/add", handlers.AddBookmark).Methods("POST")
r.HandleFunc("/api/finders", handlers.GetFinders).Methods("GET")
r.HandleFunc("/api/finders", handlers.SaveFinders).Methods("POST")
r.HandleFunc("/api/categories", handlers.GetCategories).Methods("GET")
r.HandleFunc("/api/categories", handlers.SaveCategories).Methods("POST")
r.HandleFunc("/api/pages", handlers.GetPages).Methods("GET")
r.HandleFunc("/api/pages", handlers.SavePages).Methods("POST")
r.HandleFunc("/api/pages/{id:[0-9]+}", handlers.DeletePage).Methods("DELETE")
r.HandleFunc("/api/settings", handlers.GetSettings).Methods("GET")
r.HandleFunc("/api/settings", handlers.SaveSettings).Methods("POST")
r.HandleFunc("/api/favicon", handlers.UploadFavicon).Methods("POST")
r.HandleFunc("/api/font", handlers.UploadFont).Methods("POST")
r.HandleFunc("/api/icon", handlers.UploadIcon).Methods("POST")
r.HandleFunc("/api/colors", handlers.GetColors).Methods("GET")
r.HandleFunc("/api/colors", handlers.SaveColors).Methods("POST")
r.HandleFunc("/api/colors/reset", handlers.ResetColors).Methods("POST")
r.HandleFunc("/api/colors/custom-themes", handlers.GetCustomThemesList).Methods("GET")
r.HandleFunc("/api/theme.css", handlers.CustomThemeCSS).Methods("GET")
r.HandleFunc("/api/backup", handlers.Backup).Methods("GET")
r.HandleFunc("/api/import", handlers.Import).Methods("POST")
r.HandleFunc("/api/ping", handlers.PingURL).Methods("GET")
r.HandleFunc("/health", handlers.Health).Methods("GET")
// Data files (for uploaded favicons, etc.)
r.PathPrefix("/data/").Handler(http.StripPrefix("/data/", http.FileServer(http.Dir("data/"))))
// Locales files
r.PathPrefix("/locales/").Handler(http.StripPrefix("/locales/", http.FileServer(http.Dir("locales/"))))
// Static files with proper MIME type handling
staticFS, _ := fs.Sub(embeddedFiles, "static")
staticHandler := http.FileServer(http.FS(staticFS))
r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Set correct MIME type based on file extension
ext := filepath.Ext(r.URL.Path)
if mimeType := mime.TypeByExtension(ext); mimeType != "" {
w.Header().Set("Content-Type", mimeType)
}
staticHandler.ServeHTTP(w, r)
})))
// Get port from environment or use default
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
log.Printf("Server starting on port %s", port)
log.Printf("Dashboard: http://localhost:%s", port)
log.Printf("Configuration: http://localhost:%s/config", port)
log.Fatal(http.ListenAndServe(":"+port, r))
}