Skip to content

Commit

Permalink
remove err condtion after filepath.Join statement
Browse files Browse the repository at this point in the history
  • Loading branch information
amustaque97 committed Jun 3, 2022
1 parent 36aa408 commit 62b49e9
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,18 +251,11 @@ type spaHandler struct {
// file located at the index path on the SPA handler will be served. This
// is suitable behavior for serving an SPA (single page application).
func (h spaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
var err error
// Join internally call path.Clean to prevent directory traversal
path = filepath.Join(h.staticPath, path)
if err != nil {
// if we failed to get the absolute path respond with a 400 bad request
// and stop
http.Error(w, err.Error(), http.StatusBadRequest)
return
}

// check whether a file exists at the given path
_, err = os.Stat(path)
_, err := os.Stat(path)
if os.IsNotExist(err) {
// file does not exist, serve index.html
http.ServeFile(w, r, filepath.Join(h.staticPath, h.indexPath))
Expand Down

0 comments on commit 62b49e9

Please sign in to comment.