crowdsec_manager icon indicating copy to clipboard operation
crowdsec_manager copied to clipboard

Fix for missing favicon.ico

Open Spryyyzhen opened this issue 2 months ago • 2 comments

  • curl -I localhost:8080/vite.svg inside the container returns 200 with Content-Type: text/html instead of image/svg+xml
  • The file is not embedded at all (checked with find / -iname "vite.svg" inside the container)
  • Image tag: independent
  • Result: browser tab shows a generic/default icon instead of the favicon

Spryyyzhen avatar Sep 12 '26 19:09 Spryyyzhen

CrowdSec Manager — Favicon Fix

Problem

The CrowdSec Manager web UI was not displaying its favicon.

After cloning the repo

gh repo clone hhftechnology/crowdsec_manager
cd crowdsec_manager/

The original favicon was located at:

crowdsec_manager/mobile/public/favicon.ico

It was copied into the web frontend's public directory:

crowdsec_manager/web/public/favicon.ico

The copy was performed with:

cp mobile/public/*ico web/public/

Vite then correctly included the favicon in the production build at:

/app/web/dist/favicon.ico

However, requesting /favicon.ico returned:

HTTP/1.1 200 OK
Content-Length: 2289
Content-Type: text/html; charset=utf-8

The response was actually index.html, not the favicon.

Frontend Change

In:

crowdsec_manager/web/index.html

the original Vite favicon/vite.svg reference was replaced with an explicit reference to the favicon:

<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <!-- <link rel="icon" type="image/svg+xml" href="/vite.svg" /> -->
    <link rel="icon" href="/favicon.ico" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>CrowdSec Manager</title>
  </head>
  <body>
    <div id="root"></div>
    <script type="module" src="/src/main.tsx"></script>
  </body>
</html>

The <link rel="icon"> change tells the browser to request:

/favicon.ico

This change is necessary, but it is not sufficient by itself.

Server-Side Problem

The Go server in:

crowdsec_manager/cmd/server/main.go

explicitly served the frontend assets:

router.Static("/assets", "./web/dist/assets")

but the SPA fallback served index.html for routes that weren't otherwise handled:

c.File("./web/dist/index.html")

Consequently, /favicon.ico was falling through to the SPA fallback.

This was confirmed by:

curl -I http://localhost:PORT/favicon.ico

which returned:

HTTP/1.1 200 OK
Content-Length: 2289
Content-Type: text/html; charset=utf-8

The 200 OK was misleading: the server was returning HTML rather than the ICO file.

Server-Side Fix

Add an explicit favicon route alongside the existing static asset route after line #208 of crowdsec_manager/cmd/server/main.go :

router.Static("/assets", "./web/dist/assets")
router.StaticFile("/favicon.ico", "./web/dist/favicon.ico")

This makes:

/favicon.ico

serve:

./web/dist/favicon.ico

instead of falling through to the SPA's index.html.

Why the File Location Is Correct

The favicon's path through the build is:

mobile/public/favicon.ico
        │
        │ copied
        ▼
web/public/favicon.ico
        │
        │ Vite build
        ▼
web/dist/favicon.ico
        │
        │ Go StaticFile route
        ▼
/favicon.ico

The runtime container confirmed that the file existed at:

/app/web/dist/favicon.ico

Therefore, the favicon did not need to be moved somewhere else. The problem was the Go server's routing.

Docker Build

After modifying cmd/server/main.go, rebuild the image:

docker build -t crowdsec-mgr:fav .

Then deploy the rebuilt image through the existing Compose configuration:

$ cat docker-compose.yaml 
services:
  crowdsec-manager:
#    image: hhftechnology/crowdsec-manager:latest
    image: crowdsec-mgr:fav
#    container_name: crowdsec-manager
    container_name: crowdsec-mgr
    hostname: crowdsec-mgr
    restart: unless-stopped

Final Changes

Four changes are required.

cp mobile/public/*.ico web/public/

Place the favicon file in the web tree:

cp mobile/public/*.ico web/public/

web/index.html

Replace the default Vite favicon reference:

<!-- <link rel="icon" type="image/svg+xml" href="/vite.svg" /> -->

with:

<link rel="icon" href="/favicon.ico" />

cmd/server/main.go

Add:

router.StaticFile("/favicon.ico", "./web/dist/favicon.ico")

alongside:

router.Static("/assets", "./web/dist/assets")

The favicon itself remains at:

mobile/public/favicon.ico

and is copied to:

web/public/favicon.ico

so that Vite places it in:

web/dist/favicon.ico

Rebuild and deploy

docker build -t crowdsec-mgr:fav .

Replace the image name with crowdsec-mgr:fav

docker compose up -d

The root cause was that the Go server did not explicitly serve /favicon.ico; its SPA catch-all was returning index.html instead.

iconoclasthero avatar Sep 15 '26 10:09 iconoclasthero

It should go without saying that if you don't like the favicon packaged in this repo you could substitute one you like better. There are some shield pngs in mobile/ that would work or you could e.g., steal the one from crowdsec.

iconoclasthero avatar Sep 15 '26 10:09 iconoclasthero