diff --git a/.gitignore b/.gitignore index 35748b7..1f7db33 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,10 @@ go.work # Project specific binaries erp_system +erp.db +erp.db-shm +erp.db-wal +erp_system # SQLite *.db *.db-shm diff --git a/erp.db-shm b/erp.db-shm deleted file mode 100644 index d856234..0000000 Binary files a/erp.db-shm and /dev/null differ diff --git a/erp_system b/erp_system deleted file mode 100755 index 3f7cea7..0000000 Binary files a/erp_system and /dev/null differ diff --git a/main.go b/main.go index 12277b1..d927538 100644 --- a/main.go +++ b/main.go @@ -45,6 +45,10 @@ func main() { mux := http.NewServeMux() // Static/public routes + mux.Handle("/resources/", http.StripPrefix("/resources/", http.FileServer(http.Dir("resources")))) + mux.HandleFunc("GET /favicon.ico", func(w http.ResponseWriter, r *http.Request) { + http.ServeFile(w, r, "resources/favicon.png") + }) mux.HandleFunc("GET /login", h.LoginPage) mux.HandleFunc("POST /login", h.LoginSubmit) mux.HandleFunc("POST /logout", h.Logout) diff --git a/main_test.go b/main_test.go new file mode 100644 index 0000000..a6bd3e2 --- /dev/null +++ b/main_test.go @@ -0,0 +1,42 @@ +package main_test + +import ( + "net/http" + "net/http/httptest" + "os" + "testing" +) + +func TestResources_Favicon(t *testing.T) { + // Create resources directory and dummy favicon if not exists + if _, err := os.Stat("resources"); os.IsNotExist(err) { + os.Mkdir("resources", 0755) + } + if _, err := os.Stat("resources/favicon.png"); os.IsNotExist(err) { + os.WriteFile("resources/favicon.png", []byte("dummy"), 0644) + defer os.Remove("resources/favicon.png") + } + + // Setup handler exactly as in main.go + mux := http.NewServeMux() + mux.Handle("/resources/", http.StripPrefix("/resources/", http.FileServer(http.Dir("resources")))) + mux.HandleFunc("GET /favicon.ico", func(w http.ResponseWriter, r *http.Request) { + http.ServeFile(w, r, "resources/favicon.png") + }) + + // Test request for resources path + req := httptest.NewRequest("GET", "/resources/favicon.png", nil) + w := httptest.NewRecorder() + mux.ServeHTTP(w, req) + if w.Code != http.StatusOK { + t.Errorf("GET /resources/favicon.png failed: %d", w.Code) + } + + // Test request for favicon.ico + reqIco := httptest.NewRequest("GET", "/favicon.ico", nil) + wIco := httptest.NewRecorder() + mux.ServeHTTP(wIco, reqIco) + if wIco.Code != http.StatusOK { + t.Errorf("GET /favicon.ico failed: %d", wIco.Code) + } +} diff --git a/resources/favicon.png b/resources/favicon.png new file mode 100644 index 0000000..dc7eea7 Binary files /dev/null and b/resources/favicon.png differ diff --git a/templates/layout.html b/templates/layout.html index 835bafd..f5e568e 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -4,6 +4,8 @@ + + {{.Title}} - ERP System diff --git a/templates/login.html b/templates/login.html index bb4b0a7..141f2d4 100644 --- a/templates/login.html +++ b/templates/login.html @@ -3,6 +3,7 @@ + Login - ERP System