This commit is contained in:
Victor Broman 2026-02-06 19:14:13 +01:00
parent c51da2a965
commit 656333275b
8 changed files with 53 additions and 0 deletions

4
.gitignore vendored

@ -20,6 +20,10 @@ go.work
# Project specific binaries # Project specific binaries
erp_system erp_system
erp.db
erp.db-shm
erp.db-wal
erp_system
# SQLite # SQLite
*.db *.db
*.db-shm *.db-shm

Binary file not shown.

Binary file not shown.

@ -45,6 +45,10 @@ func main() {
mux := http.NewServeMux() mux := http.NewServeMux()
// Static/public routes // 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("GET /login", h.LoginPage)
mux.HandleFunc("POST /login", h.LoginSubmit) mux.HandleFunc("POST /login", h.LoginSubmit)
mux.HandleFunc("POST /logout", h.Logout) mux.HandleFunc("POST /logout", h.Logout)

42
main_test.go Normal file

@ -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)
}
}

BIN
resources/favicon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

@ -4,6 +4,8 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/png" sizes="64x64" href="/resources/favicon.png?v=1">
<title>{{.Title}} - ERP System</title> <title>{{.Title}} - ERP System</title>
<script src="https://unpkg.com/htmx.org@2.0.4"></script> <script src="https://unpkg.com/htmx.org@2.0.4"></script>
<script src="https://cdn.tailwindcss.com"></script> <script src="https://cdn.tailwindcss.com"></script>

@ -3,6 +3,7 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/png" href="/resources/favicon.png">
<title>Login - ERP System</title> <title>Login - ERP System</title>
<script src="https://unpkg.com/htmx.org@2.0.4"></script> <script src="https://unpkg.com/htmx.org@2.0.4"></script>
<script src="https://cdn.tailwindcss.com"></script> <script src="https://cdn.tailwindcss.com"></script>