added docker setup

This commit is contained in:
2025-10-25 22:30:16 +02:00
parent cc28aa9a8e
commit 335c34ce64
5 changed files with 247 additions and 12 deletions

15
main.go
View File

@@ -8,6 +8,7 @@ import (
"mealprep/database"
"mealprep/handlers"
"net/http"
"os"
"strings"
)
@@ -15,8 +16,14 @@ func main() {
// Print startup banner
printBanner()
// Get database path from environment variable or use default
dbPath := os.Getenv("DB_PATH")
if dbPath == "" {
dbPath = "mealprep.db"
}
// Initialize database
if err := database.InitDB("mealprep.db"); err != nil {
if err := database.InitDB(dbPath); err != nil {
log.Fatalf("Failed to initialize database: %v", err)
}
defer database.DB.Close()
@@ -48,6 +55,12 @@ func main() {
})
http.HandleFunc("/logout", handlers.LogoutHandler)
// Health check endpoint (public, for Docker)
http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("OK"))
})
// Protected routes
http.HandleFunc("/", auth.RequireAuth(indexHandler))