mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-11 22:14:02 +01:00
``` git ls-files \*.js \*.go \ | xargs sed -i '1i // SPDX-FileCopyrightText: 2022 Free Mobile\n// SPDX-License-Identifier: AGPL-3.0-only\n' git ls-files \*.vue \ | xargs sed -i '1i <!-- SPDX-FileCopyrightText: 2022 Free Mobile -->\n<!-- SPDX-License-Identifier: AGPL-3.0-only -->\n' ```
37 lines
860 B
Go
37 lines
860 B
Go
// SPDX-FileCopyrightText: 2022 Free Mobile
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
package console
|
|
|
|
import (
|
|
"embed"
|
|
"net/http"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
//go:embed data/frontend
|
|
var embeddedAssets embed.FS
|
|
|
|
func (c *Component) assetsHandlerFunc(w http.ResponseWriter, req *http.Request) {
|
|
assets := c.embedOrLiveFS(embeddedAssets, "data/frontend")
|
|
upath := req.URL.Path
|
|
if !strings.HasPrefix(upath, "/") {
|
|
upath = "/" + upath
|
|
req.URL.Path = upath
|
|
}
|
|
// Serve assets using a file server
|
|
if strings.HasPrefix(upath, "/assets/") {
|
|
http.FileServer(http.FS(assets)).ServeHTTP(w, req)
|
|
return
|
|
}
|
|
|
|
// Everything else is routed to index.html
|
|
f, err := http.FS(assets).Open("index.html")
|
|
if err != nil {
|
|
http.Error(w, "Application not found.", http.StatusInternalServerError)
|
|
}
|
|
http.ServeContent(w, req, "index.html", time.Time{}, f)
|
|
f.Close()
|
|
}
|