diff options
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -23,6 +23,9 @@ import ( //go:embed templates var tmplFS embed.FS +//go:embed static +var staticFS embed.FS + //go:embed favicon.ico var favicon []byte @@ -61,6 +64,17 @@ func (handler BoxHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } if reqPath == "/" { serve(w, handler.token, "templates/index.html") + } else if strings.HasPrefix(reqPath, "/static") { + http.ServeFileFS(w, r, staticFS, reqPath) + } else if strings.HasPrefix(reqPath, "/getindex") { + token := r.Header.Get("X-Token") + if bcrypt.CompareHashAndPassword(handler.token, []byte(token)) != nil { + log.Println("unauthorized") + w.WriteHeader(http.StatusUnauthorized) + fmt.Fprint(w, "<span>Unauthorized: invalid token</span>") + return + } + http.ServeFile(w, r, filepath.Join(handler.filesPath)) } else { resourceId := path.Base(reqPath) resourcePath := filepath.Join(handler.filesPath, resourceId) |
