Skip to content

Commit

Permalink
Updating serve dir to be absolute (#863)
Browse files Browse the repository at this point in the history
  • Loading branch information
gracegoo-stripe committed May 4, 2022
1 parent 7010d31 commit 41ba354
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions pkg/cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"net/http"
"os"
"path/filepath"

"github.com/gorilla/handlers"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -32,11 +33,16 @@ func newServeCmd() *serveCmd {
dir = args[0]
}

fmt.Println("Starting static file server at address", fmt.Sprintf("http://localhost:%s", port))
http.Handle("/", http.FileServer(http.Dir(dir)))
err := http.ListenAndServe(fmt.Sprintf(":%s", port), handlers.LoggingHandler(os.Stdout, http.DefaultServeMux))
absoluteDir, err := filepath.Abs(dir)
if err != nil {
return err
}

return err
fmt.Printf("Starting server for directory %s\n", absoluteDir)

fmt.Println("Starting static file server at address", fmt.Sprintf("http://localhost:%s", port))
http.Handle("/", http.FileServer(http.Dir(absoluteDir)))
return http.ListenAndServe(fmt.Sprintf(":%s", port), handlers.LoggingHandler(os.Stdout, http.DefaultServeMux))
},
}

Expand Down

0 comments on commit 41ba354

Please sign in to comment.