Files
akvorado/console/assets.go
Vincent Bernat 8be1bca4fd license: AGPL-3.0-only
```
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'
```
2022-06-29 11:42:28 +02:00

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