1
0
Fork 0
mirror of https://github.com/Luzifer/cloudkeys-go.git synced 2024-11-14 08:52:44 +00:00
cloudkeys-go/assets.go
Knut Ahlers b0ff38946d
Fix request without filename
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2020-01-11 20:47:48 +01:00

24 lines
450 B
Go

package main
import (
"mime"
"net/http"
"path"
"path/filepath"
)
func serveAssets(res http.ResponseWriter, r *http.Request) {
var fileName = r.RequestURI[1:]
if fileName == "" {
fileName = "index.html"
}
data, err := Asset(path.Join("dist", fileName))
if err != nil {
http.Error(res, "Not found", http.StatusNotFound)
return
}
res.Header().Set("Content-Type", mime.TypeByExtension(filepath.Ext(r.RequestURI)))
res.Write(data)
}